问题描述
在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.
推荐答案
目标属性指定库目标文件所在目录的 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库输出的自定义目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!