使用“实验/文件系统"构建项目;使用 cmake
问题描述
我需要在我的项目中添加一个实验/文件系统"头
I need to add a "experimental/filesystem" header to my project
所以我使用了 -lstdc++fs 标志并与 libstdc++fs.a 链接
So I used -lstdc++fs flag and linked with libstdc++fs.a
但是,我有下一个错误:
However, I have next error:
CMakeLists.txt:9 处的 CMake 错误 (target_link_libraries):不能为不是由
构建的目标testcpp"指定链接库这个项目.
CMake Error at CMakeLists.txt:9 (target_link_libraries): Cannot specify link libraries for target "testcpp" which is not built by
this project.
但是如果我直接编译就可以了:
But if I compile directly, it`s OK:
我的错误在哪里?
推荐答案
只是 target_link_libraries()
调用必须在 add_executable()
调用之后.否则 testcpp
目标还不知道.CMake 按顺序解析所有内容.
It's just that the target_link_libraries()
call has to come after the add_executable()
call. Otherwise the testcpp
target is not known yet. CMake parses everything sequential.
所以为了完整起见,这是我测试过的示例的工作版本:
So just for completeness, here is a working version of your example I've tested:
这篇关于使用“实验/文件系统"构建项目;使用 cmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!