使用CMAKE链接外部的动态库时找不到库文件解决办法(/usr/bin/ld: cannot find lxxx)
2012-10-02 15:40
966 查看
如果你有外部已经生成的动态库文件 libtest.so,在使用CMake编译生成目标文件myproject时需要依赖该so库文件,假设文件存于{MY_PROJECT_DIR}/bin目录下,要链接成功, 需要做的是:
在CMakeLists.txt文件中加入两行
1: LINK_LIBRARIES(${MY_PROJECT_DIR}/bin) #该命令的作用相当与gcc命令的-L参数的作用
2:ADD_EXECUTABLE(myproject ${MY_PROJECT_SOURCES}) # ${MY_PROJECT_SOURCES}为myproject依赖的源文件目录
3:TARGET_LINK_LIBRARIES(myproject test)
另外,请确保LINK_LIBRARIES命令写在ADD_EXECUTABLE之前。
在CMakeLists.txt文件中加入两行
1: LINK_LIBRARIES(${MY_PROJECT_DIR}/bin) #该命令的作用相当与gcc命令的-L参数的作用
2:ADD_EXECUTABLE(myproject ${MY_PROJECT_SOURCES}) # ${MY_PROJECT_SOURCES}为myproject依赖的源文件目录
3:TARGET_LINK_LIBRARIES(myproject test)
另外,请确保LINK_LIBRARIES命令写在ADD_EXECUTABLE之前。
相关文章推荐
- 解决/usr/bin/ld: cannot find XXX
- 安装theano框架时,解决问error: /usr/bin/ld: cannot find XXX
- LAMP编译:usr bin ld cannot find lltdl 错误的解决办法
- Qt编译错误:usr/bin/ld: cannot find lxxx
- usr/bin/ld: cannot find 错误解决方法
- 解决Qt5 安装Opengl后依然出现/usr/bin/ld: cannot find lGL
- ubuntu12.04 64bit编译android ics4.0代码出现的/usr/bin/ld.bfd.real: cannot find 问题解决
- Linux /usr/bin/ld cannot find 解决
- ubuntu12.04 64bit编译android ics4.0代码出现的/usr/bin/ld.bfd.real: cannot find 问题解决
- 【转】linux /usr/bin/ld cannot find 解决
- usr/bin/ld: cannot find 错误解决方法
- usr/bin/ld: cannot find 错误解决方法和 /etc/ld.so.conf
- 解决/usr/bin/ld: cannot find *** 的错误
- /usr/bin/ld: cannot open output file a.out: Permission denied,解决办法在最后
- usr/bin/ld: cannot find 错误解决方法
- /usr/lib/ld: cannot find lxx的解决办法
- Linux下GCC编译器链接任意目录下库文件(解决错误“/usr/bin/ld: cannot find -lxxx”)
- 【转】链接任意目录下库文件(解决错误“/usr/bin/ld: cannot find -lxxx”
- usr/bin/ld: cannot find 错误解决方法
- ubuntu 编译 /usr/bin/ld: cannot find 问题解决