cmake不支持导入的库? [英] cmake doesn't support imported libraries?

查看:83
本文介绍了cmake不支持导入的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用

 add_library(libname SHARED IMPORTED)
    set_property(TARGET libname PROPERTY IMPORTED_LOCATION /<foldername>/<sub-foldername>/lib")

cmake喊叫着:

The cmake shouts :


在/CMakeLists.txt上的CMake警告(dev):28
(target_link_libraries):无法为目标$ b指定链接库$ b libname不是由该项目构建的。

CMake Warning (dev) at /CMakeLists.txt:28 (target_link_libraries): Cannot specify link libraries for target "libname" which is not built by this project.

CMake不支持此功能,但是它曾经偶然工作,因此允许
兼容。

CMake does not support this but it used to work accidentally and is being allowed for compatibility.

未设置策略CMP0016:如果仅
个参数不是目标,则target_link_libraries()报告错误。运行 cmake --help-policy CMP0016
用于策略详细信息。使用cmake_policy命令设置策略
并禁止显示此警告。此警告适用于项目开发人员。
使用-Wno-dev禁止它。

Policy CMP0016 is not set: target_link_libraries() reports error if only argument is not a target. Run "cmake --help-policy CMP0016" for policy details. Use the cmake_policy command to set the policy and suppress this warning. This warning is for project developers. Use -Wno-dev to suppress it.

如果是这样,将构建树中某个地方的库包含到另一个项目中的另一种最佳方法是什么。
我有一个库设置,另一个地方有可执行文件,它将使用库。
仔细阅读了cmake文档,感觉这将是最好的方法,但似乎只是一个破碎的片段而已。

If this is true, what is the other best way to include a library somewhere in my build tree into another project. I have a library setup and another place has executable which will be using the libraries. Reading through the cmake documentation, it felt like this would be the best way forward but seems its a broken piece which is just being supported.

推荐答案

无法为该项目未构建的目标 libname指定链接库

当您对某些目标使用 target_link_libraries 时,您要指定构建方式,
但导入的库已已构建。 CMake告诉您...

When you use target_link_libraries to some target you're specifying how to build it, but imported library is already build. CMake told you that...

将导入的目标链接到可执行文件的示例:

Example of linking imported target to executable:

add_library(boo SHARED IMPORTED)
set_target_properties(boo PROPERTIES IMPORTED_LOCATION "/path/to/boo/library")
add_executable(foo foo.cpp)
target_link_libraries(foo boo)

注意使用导入的目标

这篇关于cmake不支持导入的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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