我正在尝试在 C++ 中使用 SCHED_DEADLINE,我需要发送struct sched_attr到,ioctl所以我包含了<linux/sched/types.h>,该标头也恰好包含了strut sched_param。我还包括了<string>其中包括 c++ 的标准头文件,其中最终包括了include\\bits\\sched.h也定义了struct sched_param. 编译器(显然)并不特别喜欢这样。我在代码中使用了头保护(_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 <\n\nIn file included from src/LSM9DS0.cpp:36:\n/usr/arm-linux-gnueabihf/include/linux/sched/types.h:7:8: error: redefinition of \xe2\x80\x98struct sched_param\xe2\x80\x99\n struct sched_param {\n ^~~~~~~~~~~\nIn file included from /usr/arm-linux-gnueabihf/include/bits/sched.h:74,\n from /usr/arm-linux-gnueabihf/include/sched.h:43,\n from /usr/arm-linux-gnueabihf/include/pthread.h:23,\n from /usr/arm-linux-gnueabihf/include/c++/8/arm-linux-gnueabihf/bits/gthr-default.h:35,\n from /usr/arm-linux-gnueabihf/include/c++/8/arm-linux-gnueabihf/bits/gthr.h:148,\n from /usr/arm-linux-gnueabihf/include/c++/8/ext/atomicity.h:35,\n from /usr/arm-linux-gnueabihf/include/c++/8/bits/basic_string.h:39,\n from /usr/arm-linux-gnueabihf/include/c++/8/string:52,\n from src/LSM9DS0.cpp:20:\n/usr/arm-linux-gnueabihf/include/bits/types/struct_sched_param.h:23:8: note: previous definition of \xe2\x80\x98struct sched_param\xe2\x80\x99\n struct sched_param\nRun Code Online (Sandbox Code Playgroud)\n如果这很重要,代码就在这里。我也尝试过这种交叉编译和本地编译,都会导致问题。
\n你运气不好。这两个标头不兼容。您必须避免将两者<linux/sched/types.h>都包含<string>在同一个翻译单元中。可能值得注意的是,作为 Linux 内核头文件,前者可能不打算在 C++ 中使用,也没有尝试使其兼容。
| 归档时间: |
|
| 查看次数: |
419 次 |
| 最近记录: |