正常編譯(正常工作):如何將外部庫添加到CMakeLists?
g++ DBHandler.cpp Functions.cpp Main.cpp -I/usr/local/include -L/usr/local/lib -lconfig++ -lpqxx -lpq -o dbhandler
它單曲可能運行:
./dbhandler
的CMakeLists.txt(標準):
cmake_minimum_required(VERSION 2.8.9)
project(DBHandler)
include_directories(include)
file(GLOB SOURCES "src/*.cpp")
target_link_libraries(dbhandler config++ pqxx pq)
add_executable(dbhandler ${SOURCES})
如何改變的CMakeLists.txt並添加:
-I/usr/local/include -L/usr/local/lib -lconfig++ -lpqxx -lpq
使用cmake編譯程序?
[如何添加 「-l」(ELL)編譯器的CMake標誌的可能的複製](https://stackoverflow.com/questions/43136418/how-to-add-l-ell-compiler-flag-in-cmake) – Tsyvarev
我認爲你需要先調用add_executable來創建目標,然後指定庫與target_link_libraries。 – vre