CMake库输出的自定义目录 [英] Custom Directory for CMake Library Output

查看:1559
本文介绍了CMake库输出的自定义目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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]错误1
make [1]:*
[CMakeFiles /../ out / JE3D.dir / all]错误2
make:*** [全部]错误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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆