本文介绍了用cmake链接库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在电脑上安装了库 bcm2835
。要在c中编译程序,我必须输入:
I installed the library bcm2835
on my pc. To compile a program in c I must type:
gcc -o my_program my_program.c -l rt -l bcm2835
现在,我必须使用 cmake 。我从来没有使用过。
我必须在 cmakelists.txt的底部添加什么?
Now I must compile another program that use the same libraries with
cmake
. I have never used this.What must I add to the bottom of "cmakelists.txt"?
我尝试过:
TARGET_LINK_LIBRARIES(my_program rt)
TARGET_LINK_LIBRARIES(my_program bcm2835)
但这不起作用。
推荐答案
cmake_minimum_required (VERSION 2.6)
project( my_program )
find_library( rt_lib rt OTHER_PARAMETERS_THAT_YOU_REQUIRE_SEE_DOCUMENTATION_LINK )
find_library( bcm2835_lib bcm2835 OTHER_PARAMETERS_THAT_YOU_REQUIRE_SEE_DOCUMENTATION_LINK )
include_directories( LIST_OF_REQUIRED_INCLUDE_DIRECTORIES_SEE_DOCUMENTATION_LINK )
add_executable( my_program my_program.c )
target_link_libraries( my_program rt_lib bcm2835_lib )
和和是一些示例,由于CMake具有好的文档,您应该阅读有关命令的更多信息。
Hereand here and here are some examples and since CMake has good documentation you should read more about the commands here.
并且cmakelists.txt文件应命名为CMakeLists.txt
And cmakelists.txt files should be named CMakeLists.txt
这篇关于用cmake链接库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!