我正在 Ubuntu 中使用 cmake 编写一个 C++ 程序,它使用头文件 joystick.h
在/usr/include/linux
.默认情况下,似乎没有 make
可以找到joystick.h
在默认目录中,如果我使用 #include <joystick.h>
.因此,我添加了行 include_directories (/usr/include/linux)
至 CMakeLists.txt
以启用此 header 。
问题是,我现在遇到各种错误,例如 error: redefinition of ‘struct timeval’
和 error: redefinition of ‘struct timezone’
.这似乎是因为有一个标题 time.h
在两个/user/include
和 /usr/include/linux
.这些文件中的 header 保护是 #ifndef _TIME_H
和 #ifndef _LINUX_TIME_H
分别。因此,我能想到的唯一解决方案是将路径硬编码到joystick.h
。在我的源代码中。
因此,在我看来/usr/include/linux
由于这些重新定义问题,永远不应将其添加到搜索路径中。它是否正确?我对路径进行硬编码的解决方案是最好的解决方案吗?
最佳答案
除非有理由不这样做(而且我想可能有),否则似乎只使用 #include <linux/joystick.h>
在源文件中将是这里最简单的解决方案。
关于c++ - 如何在usr/include/linux中搜索头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27022774/