简体   繁体   English

如何在Linux的/ usr / include中强制cmake使用C ++头文件?

[英]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_DIRECTORIESlist ,该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.

相关问题 如何在cmake项目中包含来自/ usr / include的头文件? - How do I include header files from /usr/include in my cmake project? 我如何将目录中的头文件包含到 cmake 中 - How can i include header files from a directory into cmake 强制CMake使用Visual Studio将C ++编译器用于C文件 - Force CMake to use C++ compiler for C files with Visual Studio 使用Visual C ++进行Linux开发时是否可以直接使用linux文件夹/ usr / include - Is it possible to use directly the linux folder /usr/include when use Visual C++ for Linux Development 您能否强制仅在本地文件中包含 C++ header 文件(Visual Studio 2022)? - Can you force include a C++ header file in local files ONLY (Visual Studio 2022)? 在MacOSX特立独行的cmake,如何强制将/ usr / include包括在内 - cmake on macosx maverick, how to force /usr/include to be included 我可以将哪些C ++标头用于这些特定功能? Linux的 - What C++ header can I use for these specific functions ? Linux 如何使用make来维护一个通用的C ++头包含目录? - How can I use make to maintain a common C++ header include directory? 如何使用 CMake 和 -L/usr/include/mariadb/mysql -lmariadbclient 编译 C++ - How to compile C++ with CMake and -L/usr/include/mariadb/mysql -lmariadbclient 如何将构建的 C++ 库安装到 /usr/include? - How do I install a built C++ library to /usr/include?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM