【发布时间】:2022-09-23 02:16:27
【问题描述】:
我有一个结构如下所示的项目:
+project
|- include
| |- linkedlists
| |- stacks
| ...
|- lib
| |- linkedlists
| |- stacks
| ...
|- src
| ...
这些目录中的每一个都有自己的CMakeLists.txt 文件,这些文件是通过add_subdirectory() 添加的。
我在lib/linkedlists/ 中的 CMakeLists.txt 遇到问题。这是它的内容:
project(linkedlists)
# ignore the missing cmake_minimum_required() it was set in the file at the rootdir.
# added this here because I wanted to run it independently. This was correctly set in the file at the rootdir.
include_directories(../../include)
# I am nesting these vars to produce libs and executables in a specific directory structure.
# In the case of this file, it is supposed to build libs in ${CMAKE_BINARY_DIR}/libs/
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PROJECT_NAME})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PROJECT_NAME})
# add_library(single_ll SHARED single_ll.c)
add_library(single_ll STATIC single_ll.c)
add_library(double_ll SHARED double_ll.c)
add_library(circular_ll SHARED circular_ll.c)
如果库设置为SHARED,这可以正常工作。当设置为STATIC 或未指定时(在这种情况下,它会将其视为静态),会向我抛出错误:
$ make
Consolidate compiler generated dependencies of target single_ll
[ 16%] Linking C static library /linkedlists/libsingle_ll.a
ar: /linkedlists/libsingle_ll.a: No such file or directory
make[2]: *** [/linkedlists/libsingle_ll.a] Error 1
make[1]: *** [CMakeFiles/single_ll.dir/all] Error 2
make: *** [all] Error 2
我是 CMake 的初学者,我也不是共享库或静态库的专家,尽管我花了一些时间尝试在线阅读并自己弄清楚。如果我的理解存在根本性缺陷并且 CMake 的行为应如此,请告诉我一个我应该阅读的主题。
如果我的 CMakeLists.txt 文件可能有问题,请帮我纠正它。