簡體   English   中英

結構包含在兩個 header 文件中,我都沒有

[英]Struct included in two header files, neither of which I own

我正在嘗試在 c++ 中使用 SCHED_DEADLINE,我需要將struct sched_attr發送到和ioctl ,所以我包含了<linux/sched/types.h> ,即 header 也恰好包含strut sched_param 我還包括了<string> ,其中包括 c++ 的標准頭文件,最終包括include\bits\sched.h ,它也定義了struct sched_param 編譯器(顯然)並不特別喜歡這個。 我在我的代碼中使用了 header 保護( _BITS_TYPES_STRUCT_SCHED_PARAM )來讓編譯器不包含include\bits\sched.h ,但感覺應該有一種“更好”的方式。

> 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

如果這很重要,代碼就在這里 我也嘗試過這種交叉編譯和本地編譯,兩者都會導致問題。

你運氣不好。 這兩個標頭不兼容。 您只需避免將<linux/sched/types.h><string>都包含在同一個翻譯單元中。 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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM