CMake 库输出的自定义目录 [英] Custom Directory for CMake Library Output
问题描述
在 CMake 中,我似乎无法在 ../out/library 中输出我的库,只能输出库.当我执行 ../out/library 路径时,它告诉我它找不到库,好像它想链接到它一样.
In CMake, I can't seem to output my library in ../out/library, only library. When I do the ../out/library path, it tells me it can't find the library, as if it wants to link to it.
add_library(../out/JE3D ../source/CDeviceLayerSDL.cpp)
还有更多文件,我只是节省空间.当我这样做时,我收到此错误.
There's more files, I'm just saving space. When I do that, I get this error.
链接 CXX 静态库 lib../out/JE3D.a/usr/bin/ar: lib../out/JE3D.a: 没有那个文件或目录make[2]: * [lib../out/JE3D.a] 错误 1make[1]: * [CMakeFiles/../out/JE3D.dir/all] 错误 2make: *** [all] 错误 2
Linking CXX static library lib../out/JE3D.a /usr/bin/ar: lib../out/JE3D.a: No such file or directory make[2]: * [lib../out/JE3D.a] Error 1 make[1]: * [CMakeFiles/../out/JE3D.dir/all] Error 2 make: *** [all] Error 2
推荐答案
LIBRARY_OUTPUT_DIRECTORY
目标属性指定将构建库目标文件的目录.
The LIBRARY_OUTPUT_DIRECTORY
target property specifies the directory where library target files will be built.
set_target_properties(JE3D PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/library)
如果所有库都在一个目录中,我发现设置 CMAKE_LIBRARY_OUTPUT_DIRECTORY
变量更方便,该变量用于在创建目标时初始化 LIBRARY_OUTPUT_DIRECTORY
属性.
If all the libraries are in one directory, I find it more convenient to set the CMAKE_LIBRARY_OUTPUT_DIRECTORY
variable, which is used to initialize the LIBRARY_OUTPUT_DIRECTORY
property when creating a target.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/library)
如果您的目标是静态库,请检查评论
Check comments if your target is a static library
这篇关于CMake 库输出的自定义目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!