- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一个使用 fast-cpp-csv-parser 的项目和 date库并想添加 zmq (0mq) 但是无法让 CMakeList 工作。
以下是一个有效的 CMakeList.txt
:
cmake_minimum_required(VERSION 3.7)
project(sample_project)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES source/main.cpp include/csv.h include/date.h)
find_package (Threads)
add_executable(sample_project ${SOURCE_FILES})
target_link_libraries (sample_project ${CMAKE_THREAD_LIBS_INIT})
根据 zmq instructions必须将以下内容添加到 CMakeLists.txt
(ZMQ 和 CPPZMQ 已安装)。
find_package(cppzmq)
if(cppzmq_FOUND)
include_directories(${cppzmq_INCLUDE_DIR})
target_link_libraries(sample_project ${cppzmq_LIBRARY})
endif()
当我将上面的代码添加到 CMakeLists.txt
时,它看起来像这样:
cmake_minimum_required(VERSION 3.7)
project(sample_project)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES source/main.cpp include/csv.h include/date.h)
find_package(cppzmq)
if(cppzmq_FOUND)
include_directories(${cppzmq_INCLUDE_DIR})
target_link_libraries(sample_project ${cppzmq_LIBRARY})
endif()
find_package (Threads)
add_executable(sample_project ${SOURCE_FILES})
target_link_libraries (sample_project ${CMAKE_THREAD_LIBS_INIT})
并导致以下错误:
CMake Warning at /usr/local/share/cmake/cppzmq/cppzmqConfig.cmake:44 (find_package):
By not providing "FindZeroMQ.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "ZeroMQ", but
CMake did not find one.
Could not find a package configuration file provided by "ZeroMQ" with any
of the following names:
ZeroMQConfig.cmake
zeromq-config.cmake
Add the installation prefix of "ZeroMQ" to CMAKE_PREFIX_PATH or set
"ZeroMQ_DIR" to a directory containing one of the above files. If "ZeroMQ"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:7 (find_package)
CMake Error at CMakeLists.txt:10 (target_link_libraries):
Cannot specify link libraries for target "sample_project" which is not
built by this project.
-- Configuring incomplete, errors occurred!
See also "/home/greg/CLionProjects/sample_project/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/home/greg/CLionProjects/sample_project/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
如何使用 CMakeLists.txt
正确添加额外的库?
最佳答案
您必须重新排序您的 CMakeLists.txt
,以便 target_link_libraries
位于 add_executable
之后。
例如:
cmake_minimum_required(VERSION 3.7)
project(sample_project)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES source/main.cpp include/csv.h include/date.h)
find_package(cppzmq)
if(cppzmq_FOUND)
include_directories(${cppzmq_INCLUDE_DIR})
endif()
find_package (Threads)
add_executable(sample_project ${SOURCE_FILES})
target_link_libraries (sample_project ${CMAKE_THREAD_LIBS_INIT})
if(cppzmq_FOUND)
target_link_libraries(sample_project ${cppzmq_LIBRARY})
endif()
顺便说一句,我建议使用 target_include_directories
而不是 include_directories
。这也允许将所有 cppzmq
相关的东西打包在一起。
关于c++ - 使用多个库时,在 CMakeList 中配置 target_link_libraries 的正确方法是什么?获取无法指定链接库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46702224/
我正在尝试链接我的 CMakeLists.txt 中的 Curl 库,我知道我应该要求包添加可执行文件并链接库,但我不知道如何调用变量名称以及我应该在哪里查看对于他们,你知道我应该去哪里找吗?有没有办
我有一个 cmake 项目,我想在其中添加一个包含 matlab 引擎的类。为了编译它,我需要包含两个库 eng和 mx ,我通过添加 target_link_libraries( ${TARGE
我是 Linux 新手。我在 CMakeLists.txt 中看到以下内容; target_link_libraries(app wiringPi
我有一个小型静态库,它需要 boost 头文件,并且需要包含目录中的“include”目录。 ... add_library(alib STATIC ...) target_include_direc
是否有任何用例 target_link_libraries(my-lib x y z) add_dependencies(my-lib x) # this is not just a waste of
我想知道默认的 target_link_libraries 隐私是什么。 我在 CMake 中添加了一行: target_link_libraries(myTarget library
出于多种原因,我必须通过自定义命令手动生成静态库。 但是,似乎自定义命令仅在目标明确请求其输出文件时才执行。 如果我尝试将生成的静态库与 target_link_libraries 链接起来, CMa
案例: 我已经声明了一个函数 setup_target_for_coverage在单独的 .cmake 脚本中,添加到 CMAKE_MODULE_PATH , 它为代码覆盖率分析准备了一个目标 ( m
假设我有一个可执行的 Alpha,它必须链接到一个共享库 Beta。 Beta 本身依赖于共享库 Gamma。 Gamma 对我来说已经存在,但我必须使用 cmake 自己编译 Alpha 和 Bet
我的项目中有很多库,还有很多单独的应用程序。我的一些库有依赖库,其中一些是外部库,我想要一种使应用程序 CMakeList.txt 文件更简单的方法。我希望使用宏来简化。 下面是一个大大简化的测试用例
我想为 C 代码测试创建模拟函数,并了解到在 target_link_libraries() 中可以选择包装函数,其工作方式类似于模拟,但不明白它是如何工作的? target_link_librari
我有一个示例库和两个符号链接(symbolic link): libname.so -> libname.so.3 libname.so.3 -> libname.so.3.0 当我使用此命令时: t
我一次又一次地与链接器问题作斗争,因为必须以正确的顺序指定 TARGET_LINK_LIBRARIES 中的所有库。但是我怎样才能确定这个顺序呢? 示例: 我有以下库 libA depends on
我正在使用 CMake 3.8.2(与 JetBrains CLion 一起提供)并链接自定义项目的几个静态库。 因为我需要保留静态符号(遗留),所以我将自己的程序部分包含在 target_link_
我有一个 CMake 多重定义链接问题,可执行文件依赖于包含静态库的共享库。 我创建了一个依赖于静态库 bar 的共享库 foo。 add_library(foo SHARED foo.cpp) ta
是否可以告诉 cmake 链接到 静态库 而不是 共享? 在我的 CMakeLists.txt 顶部,我配置了以下内容: set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CM
不知何故,我正在努力找出是否可以在 CMake 中定义导入的库,指定目标属性(include_directories 和库路径),并希望一旦我将该项目添加到另一个项目中的 target_link_li
我将开始声明我在 Cmake 问题上几乎完全是哑巴。 我有以下用于 Kdevelop 4.1 项目的 CMakeLists.txt: project(uart) find_package(KDE4 R
我是 CMake 新手,对与 target_link_libraries() 相关的 PUBLIC、PRIVATE 和 INTERFACE 关键字有点困惑。文档提到它们可用于在一个命令中指定链接依赖项
所以我在使用 CMake 构建我的软件时遇到了一个非常头疼的问题。 我正在静态构建第三方库 (dlib),它需要 zlib 和 libpng(两者都是静态的,我预先构建了这些)库来支持 PNG 功能。
我是一名优秀的程序员,十分优秀!