gpt4 book ai didi

CMake 添加子目录错误 : "When specifying an out-of-tree source a binary directory must be explicitly specified"

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:08:48 31 4
gpt4 key购买 nike

我的目录结构如下:

root
libA
CMakeLists.txt
ClassA.cpp
libB
CMakeLists.txt
ClassB.cpp
sharedCode
enums.h
AbstractClass.h

CMake文件中如何包含sharedCode目录?这样 classA(在 libA 中)和 classB(在 libB 中)都可以使用 enums.h 和 AbstractClass.h?

在我尝试使用的 CMakeLists.txt 中:

add_subdirectory(../sharedCode)

但它给出了错误

  add_subdirectory not given a binary directory but the given source
directory "/root/sharedCode" is not
a subdirectory of "root/libA". When
specifying an out-of-tree source a binary directory must be explicitly
specified.

最佳答案

如错误所述,当指定当前树之外的相对源目录时,您还必须提供第二个参数来指定将放置生成的二进制文件的目录。

Here's the documentation对于 add_subdirectory:

The binary_dir specifies the directory in which to place the output files. If it is a relative path it will be evaluated with respect to the current output directory, but it may also be an absolute path. If binary_dir is not specified, the value of source_dir, before expanding any relative path, will be used (the typical usage). The CMakeLists.txt file in the specified source directory will be processed immediately by CMake before processing in the current input file continues beyond this command.

关于CMake 添加子目录错误 : "When specifying an out-of-tree source a binary directory must be explicitly specified",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33896389/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com