我正在使用fast-cpp-csv-parser和date库的项目,并且想要添加zmq(0mq)但无法使CMakeList正常工作。使用多个库时,在CMakeList中配置target_link_libraries的正确方法是什么?获取无法指定链接库错误
下面是一个工作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
附加库?
问题是cppzmq无法找到libzmq。也许一些建议[这里](https://github.com/zeromq/cppzmq/issues/127)可能会有所帮助。 – Mark