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

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

问题描述

我的问题是如何获取CMake将一个可执行文件(由CMake构建)链接到一个外部共享库,不是由CMake(我只有二进制文件)。只是做target_link_libraries给出以下错误:

My question is how to get CMake to link an executable (built by CMake) to an external shared library that is not build by CMake (I only have the binaries). Just doing target_link_libraries gives the following error:

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)

TARGET_LINK_LIBRARIES(GLBall ${CMAKE_BINARY_DIR}/res/mylib.so)

二进制dir,bin / res)。

(I copied the library into the binary dir, bin/res).

看来CMake只想链接到库CMake build ...

It seems that CMake only wants to link to libraries CMake builds itself...

我尝试使用find_library:

I tried using find_library:

FIND_LIBRARY(RESULT mylib.so PATHS ${CMAKE_BINARY_DIR}/res)

其中RESULT-NOTFOUND失败。将HINTS替换为PATHS会产生相同的错误。

Which fails with RESULT-NOTFOUND. Substituting HINTS for PATHS produces the same error.

CMake能否执行此操作?任何帮助

Is CMake capable of doing this? Any help is appreciated

感谢

推荐答案

LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/res)

然后只需执行

TARGET_LINK_LIBRARIES(GLBall mylib)

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

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