![](/img/trans.png)
[英]How to include external library (boost) into CLion C++ project with CMake?
[英]How to add library to C++ Project using homebrew, cMake and, cLion
我對 C++ 真的很陌生,我有點困惑。
我正在嘗試將此庫添加到我的項目( https://github.com/mrtazz/restclient-cpp )。 我已經使用 Homebrew 安裝了它
brew tap mrtazz/oss
brew install restclient-cpp
然后我嘗試通過包含和鏈接 Homebrew 安裝目錄將庫添加到我的 CMakeLists。
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(POS)
set(CMAKE_CXX_STANDARD 14)
include_directories(/usr/local/include)
link_directories(/usr/local/lib)
add_library(
restclient-cpp STATIC
connection.h
helpers.h
restclient.h
version.h
)
add_executable(POS main.cpp program.cpp program.h programs/find.cpp programs/find.h tools/db.cpp tools/db.h)
target_link_libraries(POS PUBLIC restclient-cpp)
然后我得到這個錯誤...
CMake Error at CMakeLists.txt:16 (add_library):
Cannot find source file:
connection.h
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
CMake Error at CMakeLists.txt:16 (add_library):
No SOURCES given to target: restclient-cpp
我知道目錄有問題,但我無法弄清楚,我將非常感謝盡可能多的信息。 我只是想找點樂子,我不知道為什么我不能將這個簡單的庫添加到我的構建中。
謝謝你。
您正在嘗試將頭文件添加到add_library
命令。 這些文件需要位於您通過include_directory
包含的目錄中。 您也不應該將頭文件放入add_executable
命令。
要鏈接現有庫,您可以調用target_link_libraries
。
例子:
include_directories(${MY_INCLUDE_DIRS})
add_executable(main source.cpp)
target_link_libraries(main extlib)
最好找到一個簡單的 CMake 設置並嘗試將其用作模板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.