Cmake基本库链接问题 [英] Cmake basic library linking problem

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

问题描述

我有一个简单的问题,链接库与CMake(我不知道CMake很好)。
我的配置如下:

  project / src / CMakeLists.txt(所有.cpp和.h文件)
project / support / linux / gmp / include / gmp.h
project / support / linux / gmp / include / gmpxx.h
project / support / linux / gmp / include / libgmp .a
project / support / linux / gmp / include / libgmpxx.a

包括库gmp在编译过程中? (我失去了FIND_PACKAGE,INCLUDE_DIRECTORIES,TARGET_LINK_LIBRARIES,ADD_LIBRARY ...命令)



非常感谢。



第一步


$ b

使用 find_package 找到库。

  find_package(GMP REQUIRED)

第二步



使用 include_directories 以包含库头文件。

  include_directories($ {GOBJECT_INCLUDE_DIR})

第三步



使用 target_link_libraries 将您的二进制文件链接到库。

  add_executable(ExecutableName Main.cpp)
target_link_libraries(ExecutableName $ {GOBJECT_LIBRARIES})


I have a simple problem with the linking of libraries with CMake (I don't know CMake very well). My configuration is the following :

project/src/CMakeLists.txt (with all .cpp and .h files)
project/support/linux/gmp/include/gmp.h
project/support/linux/gmp/include/gmpxx.h
project/support/linux/gmp/include/libgmp.a
project/support/linux/gmp/include/libgmpxx.a

How to include the library gmp in the process of compilation ? (I am lost between FIND_PACKAGE, INCLUDE_DIRECTORIES, TARGET_LINK_LIBRARIES, ADD_LIBRARY ... commands)

Thank you very much.

解决方案

CMake is not so hard to understand.

First Step

Use find_package to locate the libary.

find_package(GMP REQUIRED)

Second step

Use include_directories to include the libary header files.

include_directories(${GOBJECT_INCLUDE_DIR})

Third Step

Use target_link_libraries to link your binary against the libary.

add_executable(ExecutableName Main.cpp)
target_link_libraries(ExecutableName ${GOBJECT_LIBRARIES})

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

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