我的项目结构如下:
include (directory for header files)
src (directory for source files)
CMakeLists.txt
Build
我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.12)
project(Gateway)
set(CMAKE_CXX_STANDARD 17)
# List all your source files
set(SOURCES
src/main.cpp
src/datamap.cpp
src/datapoint.cpp
src/logger.cpp
src/meter.cpp
src/Puller.cpp
src/pusher.cpp
src/resetDatapoint.cpp
src/trace.cpp
)
# Create the executable target and specify the source files
add_executable(Gateway ${SOURCES})
# Include directories for header files
target_include_directories(Gateway PRIVATE include)
find_package(PahoMqttCpp REQUIRED)
target_link_libraries(Gateway PahoMqttCpp)
find_package(croncpp REQUIRED)
target_link_libraries(Gateway croncpp)
我想将UnQLite库添加到我的项目中。我从github克隆了repo,然后创建了一个构建目录,并构建了它。但是,当我在CMakelist中添加这些行以将库链接到我的项目时,我得到了一个错误。
find_library(UNQLITE_LIBRARY NAMES unqlite)
if (UNQLITE_LIBRARY)
target_link_libraries(Gateway ${UNQLITE_LIBRARY})
else ()
message(FATAL_ERROR "UNQLITE_LIBRARY not found")
endif ()
CMake Error at CMakeLists.txt:48 (message):
UNQLITE_LIBRARY not found
-- Configuring incomplete, errors occurred!
1条答案
按热度按时间gg0vcinb1#
Unqlite库也使用CMake构建系统,因此您可以将unqlite库添加为项目的子模块(例如,
external/unqlite
的Git子模块)并执行以下操作:你甚至可以更进一步,使用CMake的
ExternalProject
功能直接从GitHub提取源代码,作为你自己构建过程的一部分。this question就是一个例子。