CMake 错误: "add_subdirectory not given a binary directory"
CMake Error: "add_subdirectory not given a binary directory"
我正在尝试将Google测试集成到更大项目的子项目中,但找不到令我满意的解决方案。
我有两个约束:
- Google Test的源代码已经在项目结构中的某个地方(因此使用URL从git存储库下载它不是一种选择(
- 谷歌测试的源代码不是我的子项目的子目录(也永远不会(
所以当我尝试做这样的事情时:
add_subdirectory( ${GOOGLETEST_PROJECT_LOCATION})
我收到了:
CMake Error at unit_tests/CMakeLists.txt:10 (add_subdirectory):
add_subdirectory not given a binary directory but the given source
directory "${GOOGLETEST_PROJECT_LOCATION}" is not a subdirectory of
"${UNIT_TEST_DIRECTORY}". When
specifying an out-of-tree source a binary directory must be explicitly
specified.
另一方面,也许ExternalProject_Add
可能是一个解决方案,但当我根本不想下载源代码并使用项目中特定位置的源代码时,我不知道该如何使用它。
项目结构看起来更像这样:
3rdparty
|--googletest
...
subproject
|--module1
|--file1.cpp
|--CMakeLists.txt
|--module2
|--file2.cpp
|--CMakeLists.txt
|--include
|--module1
|--file1.h
|--module2
|--file2.h
|--unit_test
|--module1
|--file1test.cpp
|--module2
|--file2test.cpp
|--CMakeLists.txt
|--CMakeLists.txt
CMakeLists.txt
错误消息很清楚 - 您还应该为 googletest 指定构建目录。
# This will build googletest under build/ subdirectory in the project's build tree
add_subdirectory( ${GOOGLETEST_PROJECT_LOCATION} build)
为调用提供相对路径(作为源目录(add_subdirectory
时,CMake 会自动对生成目录使用相同的相对路径。
但是在绝对源路径的情况下(当此路径不在源树中时(,CMake 无法猜测构建目录,您需要明确提供它:
另请参阅有关add_subdirectory
命令的文档。
我觉得有义务对此发表评论,因为这是我在谷歌搜索此错误时排名靠前的搜索结果。
对我来说,我显然是个白痴:我已经修改了项目src
目录中的CMakeLists.txt
文件,但我没有意识到该文件已被锁定,即使我按 Ctrl+S 也没有保存 VS Code。 检查 VS Code 中的文件选项卡,看看那里是否有白点, 指示文件未保存。按 Ctrl+S,看看右下角是否出现一个弹出窗口,提示您以超级用户身份重试。
我仍然有错误,但它们是对我的项目有意义的新错误。
相关文章:
- LeetCode 1011.Binary Search,C++和Python的想法相同,但输出不同
- 从Qt QJsonDocument::toBinaryData使用non-Qt读取Binary Json?
- 如何使用curl c ++源代码发布wav文件数据,如何使用c ++使用--data-binary?
- CMake 错误: "add_subdirectory not given a binary directory"
- 使用提升从 pid 获取"binary file"/"executable"的路径?
- LeetCode #617 "Merge Two Binary Trees"使用C++
- 如何修复张量流中的"Non-OK-status: Not found: Op type not registered 'NoOp' in binary running"
- 如何修复类"Invalid operands to binary expression "类" to "类" "错误 (repl.it)
- 'context string for the given token'是什么意思?
- 如何修复C++中的'Invalid operands to binary expression'错误
- 在 Golang 中 binary.write 的C++等价物是什么?
- C++ EXC_BAD_ACCESS (Binary Tree)
- 我必须在 [ios::binary] 模式下打开文件才能获得其大小
- std::ios::binary 或 std::ifstream::binary 和类似
- 使用 ReadFile WinAPI 读取'Binary'文件
- Java Thrift Client and Binary data
- 计算"copying a binary file in c++ on linux"消耗时间的最佳方法是什么?
- 使用 std::sort 时"invalid operands to binary expression"
- 代码不适用于"Modifying a data in a Binary file"
- 日蚀月神与明格:"Launch failed. Binary not found."