CMake 和绝对头路径
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在 CMakeLists.txt 中需要类似的内容:
You need something like this in CMakeLists.txt:
设置正确的包含路径:假设您的 Utils 目录位于 /exp/appstat/benbou/multiboost 中,那么 cmake (实际上是 gcc)必须知道这一点:
或者将其作为传递的选项传递可能更方便命令行:
set the correct include path: suppose your Utils directory is in /exp/appstat/benbou/multiboost, then cmake (well actually, gcc) has to know this:
or it might be more convenient to pass this as an option which is passed on the command line: