CMake 和绝对头路径

发布于 2024-09-24 21:02:44 字数 921 浏览 8 评论 0原文

我正在尝试使用 CMake 构建我的 C++ 项目,但标头路径存在问题。

由于我使用了在多个目录中组织的大量类,因此我所有的 include 语句都带有绝对路径(因此不需要使用“../../”),但是当尝试创建 CMake 生成的 Makefile 时,它​​只是不这样做不工作。

有谁知道如何在 CMakeLists.txt 中指定所有包含内容都带有绝对路径?


我尝试制作

时的输出 〜/multiboost/BanditsLS/GenericBanditAlgorithmLS.h:45:25:Utils/Utils.h:没有这样的文件或目录
〜/ multiboost / BanditsLS / GenericBanditAlgorithmLS.h:46:35:Utils / StreamTokenizer.h:没有这样的文件或目录

我的 CMakeLists.txt 文件:

#The following command allows the use of the "file" command
cmake_minimum_required(VERSION 2.6)  

#The declaration of the project
project(multiboost)  

#This allows recursive parsing of the source files
file(
    GLOB_RECURSE
    source_files
    *
    )  
list(REMOVE_ITEM source_files ./build/* )

#This indicates the target (the executable)  
add_executable(
    multiboost
    ${source_files} #EXCLUDE_FROM_ALL build/
    )

I'm trying to use CMake to build my C++ project and I have a problem in the header paths.

Since I'm using a lot of classes organized in several directories, all my include statements are with absolute paths (so no need to use "../../") but when try to make the CMake-generated Makefile it just doesn't work.

Does anyone know how to specify in CMakeLists.txt that all the includes are with absolute paths?


My output when trying to make


~/multiboost/BanditsLS/GenericBanditAlgorithmLS.h:45:25: Utils/Utils.h: No such file or directory
~/multiboost/BanditsLS/GenericBanditAlgorithmLS.h:46:35: Utils/StreamTokenizer.h: No such file or directory

My CMakeLists.txt file :

#The following command allows the use of the "file" command
cmake_minimum_required(VERSION 2.6)  

#The declaration of the project
project(multiboost)  

#This allows recursive parsing of the source files
file(
    GLOB_RECURSE
    source_files
    *
    )  
list(REMOVE_ITEM source_files ./build/* )

#This indicates the target (the executable)  
add_executable(
    multiboost
    ${source_files} #EXCLUDE_FROM_ALL build/
    )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入画浅相思 2024-10-01 21:02:44

您在 CMakeLists.txt 中需要类似的内容:

SET(BASEPATH "${CMAKE_SOURCE_DIR}")
INCLUDE_DIRECTORIES("${BASEPATH}")

You need something like this in CMakeLists.txt:

SET(BASEPATH "${CMAKE_SOURCE_DIR}")
INCLUDE_DIRECTORIES("${BASEPATH}")
走过海棠暮 2024-10-01 21:02:44

设置正确的包含路径:假设您的 Utils 目录位于 /exp/appstat/benbou/multiboost 中,那么 cmake (实际上是 gcc)必须知道这一点:

include_directories( /exp/appstat/benbou/multiboost )

或者将其作为传递的选项传递可能更方便命令行:

include_directories( ${MyProjectRoot} )

cmake -DMyProjectRoot=/exp/appstat/benbou/multiboost    

set the correct include path: suppose your Utils directory is in /exp/appstat/benbou/multiboost, then cmake (well actually, gcc) has to know this:

include_directories( /exp/appstat/benbou/multiboost )

or it might be more convenient to pass this as an option which is passed on the command line:

include_directories( ${MyProjectRoot} )

cmake -DMyProjectRoot=/exp/appstat/benbou/multiboost    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文