CMake 链接到外部库 [英] CMake link to external library

查看:29
本文介绍了CMake 链接到外部库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 CMake 将可执行文件链接到不在同一 CMake 项目中构建的外部共享库?

How to get CMake to link an executable to an external shared library that is not build within the same CMake project?

只是做 target_link_libraries(GLBall ${CMAKE_BINARY_DIR}/res/mylib.so) 给出错误

make[2]: *** No rule to make target `res/mylib.so', needed by `GLBall'.  Stop.
make[1]: *** [CMakeFiles/GLBall.dir/all] Error 2
make: *** [all] Error 2
(GLBall is the executable)

在我将库复制到二进制目录后bin/res.

after I copied the library into the binary dir bin/res.

我尝试使用 find_library(RESULT mylib.so PATHS ${CMAKE_BINARY_DIR}/res)

RESULT-NOTFOUND 失败.

推荐答案

首先设置库搜索路径:

link_directories(${CMAKE_BINARY_DIR}/res)

然后就去做

target_link_libraries(GLBall mylib)

这篇关于CMake 链接到外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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