[英]How can I force cmake to use C++ header files in /usr/include in Linux?
I have a cmake project that uses a header installed in /usr/include
, let's call it freeglut.h
. 我有一个cmake项目,该项目使用安装在
/usr/include
的标头,我们将其称为freeglut.h
。 When I use find_package(GLUT)
I get ${GLUT_INCLUDE_DIR}
pointing to /usr/include
. 当我使用
find_package(GLUT)
我会得到${GLUT_INCLUDE_DIR}
指向/usr/include
。 All's well. 很好
Now, I'm adding CUDA, which keeps its own copies of these and other headers in one of the paths included with find_package(CUDA)
. 现在,我添加了CUDA,它在
find_package(CUDA)
随附的路径之一中保留了这些标题和其他标题的副本。 Normally I would resolve this by placing ${GLUT_INCLUDE_DIR}
before ${CUDA_INCLUDE_DIRS}
in include_directories()
. 通常,我可以通过在
include_directories()
${CUDA_INCLUDE_DIRS}
${GLUT_INCLUDE_DIR}
放在${GLUT_INCLUDE_DIR}
之前来解决此问题。 However, on Unix systems cmake, in UnixPaths.cmake
, maintains a list
called CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
, which contains /usr/include
and apparently keeps cmake from emitting -I<dir>
arguments for the compiler for the directory /usr/include
, meaning that the compiler searches the CUDA path first, and uses the freeglut.h
header found there. 但是,在Unix系统上,cmake在
UnixPaths.cmake
中维护一个名为CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
的list
,该list
包含/usr/include
并显然使cmake不会为目录/usr/include
的编译器发出-I<dir>
参数,这意味着编译器首先搜索CUDA路径,并使用在那里找到的freeglut.h
标头。
I have tried using list(REMOVE_ITEM ...
to remove /usr/include
from the CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
list, but that didn't change the compiler commands that cmake made. 我尝试使用
list(REMOVE_ITEM ...
从CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
列表中删除/usr/include
,但这并没有改变cmake生成的编译器命令。
I could of course start hacking around with the CUDA installation, delete the headers I don't want, or modify the CUDA_INCLUDE_DIRS
variable, but is there a clean way to tell cmake to use the system header files first, if they exist? 我当然可以开始使用CUDA安装,删除不需要的头文件,或修改
CUDA_INCLUDE_DIRS
变量,但是有一种干净的方法告诉cmake首先使用系统头文件(如果存在)吗?
I suppose the -idirafter
flag should help you: 我想
-idirafter
标志应该可以帮助您:
-idirafter dir
-idirafter目录
Search dir for header files, but do it after all directories specified with -I and the standard system directories have been exhausted.
在dir中搜索头文件,但是在用-I指定的所有目录和标准系统目录用完后执行此操作。 dir is treated as a system include directory.
dir被视为系统包含目录。
https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html
You can use it like this to lower CUDA include dirs priority: 您可以像这样使用它来降低CUDA包含目录优先级:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -idirafter /usr/include/<CUDA_includes>")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.