1

I am trying to play with SCHED_DEADLINE in c++, I needed to send struct sched_attr to and ioctl so I included <linux/sched/types.h>, that header also happens to include strut sched_param. I also included <string> which includes the standard headers for c++ which eventually includes include\bits\sched.h which also defines struct sched_param. The compiler (obviously) doesn't particularly like this. I used the header guard (_BITS_TYPES_STRUCT_SCHED_PARAM) in my code to get the compiler to not include include\bits\sched.h, but it feels like there should be a "better" way.

> Executing task in folder sched_deadline_testing: arm-linux-gnueabihf-g++ -o LSM9DS0 src/LSM9DS0.cpp -Wall --pedantic <

In file included from src/LSM9DS0.cpp:36:
/usr/arm-linux-gnueabihf/include/linux/sched/types.h:7:8: error: redefinition of ‘struct sched_param’
 struct sched_param {
        ^~~~~~~~~~~
In file included from /usr/arm-linux-gnueabihf/include/bits/sched.h:74,
                 from /usr/arm-linux-gnueabihf/include/sched.h:43,
                 from /usr/arm-linux-gnueabihf/include/pthread.h:23,
                 from /usr/arm-linux-gnueabihf/include/c++/8/arm-linux-gnueabihf/bits/gthr-default.h:35,
                 from /usr/arm-linux-gnueabihf/include/c++/8/arm-linux-gnueabihf/bits/gthr.h:148,
                 from /usr/arm-linux-gnueabihf/include/c++/8/ext/atomicity.h:35,
                 from /usr/arm-linux-gnueabihf/include/c++/8/bits/basic_string.h:39,
                 from /usr/arm-linux-gnueabihf/include/c++/8/string:52,
                 from src/LSM9DS0.cpp:20:
/usr/arm-linux-gnueabihf/include/bits/types/struct_sched_param.h:23:8: note: previous definition of ‘struct sched_param’
 struct sched_param

The code is here if that's important. I have also tried this cross compiling, and compiling locally, both cause the issue.

1 Answer 1

5

You're out of luck. The two headers are incompatible. You simply must avoid including both <linux/sched/types.h> and <string> into the same translation unit. It's probably worth noting that being a Linux kernel header, the former is probably not intended to be used in C++, nor has there been an attempt to make it compatible.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually making Linux headers C++ compatible has been actively opposed in the past by the ones in power. LKML FAQ 15.3. The argument being made is quite broken, but good luck changing their minds about it...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.