Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefinition errors between libiio and kernel iio include files #758

Closed
gwendalcr opened this issue Nov 10, 2021 · 1 comment · Fixed by #768
Closed

Redefinition errors between libiio and kernel iio include files #758

gwendalcr opened this issue Nov 10, 2021 · 1 comment · Fixed by #768

Comments

@gwendalcr
Copy link
Contributor

Writing an application that including libiio iio.h for handling iio buffers and kernel iio include files for handling events, there are redefinition errors between /usr/include/linux/iio/types.h and /usr/include/iio.h:

/usr/include/linux/iio/types.h:14:6: error: redefinition of 'iio_chan_type'
enum iio_chan_type {                                                          
     ^                                                                        
/usr/include/iio.h:94:6: note: previous definition is here
enum iio_chan_type {            
     ^              

When compiling on linux architecture, would it make sense for ./iio.h to include <linux/iio/types.h>?

gwendalcr added a commit to gwendalcr/libiio that referenced this issue Nov 15, 2021
To prevent conflicts when iio.h and /usr/include/linux/iio/types.h
are both included, rename iio_chan_type libiio_chan_type.

Check CI/travis/check_kernel.sh still works.

Fixes analogdevicesinc#758.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
gwendalcr added a commit to gwendalcr/libiio that referenced this issue Nov 15, 2021
enum iio_chan_type and iio_modifier are already defined in
/usr/include/linux/iio/types.h on linux systems.
If an application needs to include both (to support iio events for
instance), compiler will complains these enums are defined twice.

This patch is not without problem:
- it works only if compiler supports __has_include (C++17, not 11).
- linux system must have latest kernel-headers installed:
IIO_MOD_O2 modifier has been added to linux 5.9 kernel.

Alter CI/travis/check_kernel.sh accordingly, check it still passes.

Fixes analogdevicesinc#758.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
gwendalcr added a commit to gwendalcr/libiio that referenced this issue Nov 16, 2021
enum iio_chan_type and iio_modifier are already defined in
/usr/include/linux/iio/types.h on linux systems.
If an application needs to include both (to support iio events for
instance), compiler will complains these enums are defined twice.

This patch is not without problem:
- linux system must have latest kernel-headers installed:
IIO_MOD_O2 modifier has been added to linux 5.9 kernel.

Alter CI/travis/check_kernel.sh accordingly, check it still passes.

Fixes analogdevicesinc#758.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
pcercuei added a commit that referenced this issue Nov 29, 2021
Add the missing enums from <linux/iio/types.h> and protect all of them
from double-definition by wrapping them with the header's protect
guards.

Fixes #758.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
pcercuei added a commit that referenced this issue Nov 29, 2021
Add the missing enums from <linux/iio/types.h> and protect all of them
from double-definition by wrapping them with the header's protect
guards.

Fixes #758.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
pcercuei added a commit that referenced this issue Dec 3, 2021
Add the missing enums from <linux/iio/types.h> and protect all of them
from double-definition by wrapping them with the header's protect
guards.

Fixes #758.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
@gwendalcr
Copy link
Contributor Author

An issue remains with IIO_CHAN_TYPE_UNKNOWN, which is now used to support hwmon (commit e965bb1 ("Add support for hardware monitoring (hwmon) devices"): It is used in iio.h:

HWMON_CHAN_TYPE_UNKNOWN = IIO_CHAN_TYPE_UNKNOWN,

If the iio types definitions come from the kernel include file, IIO_CHAN_TYPE_UNKNOWN will not be defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant