[英]Issue linking c++ library with cmake
我正在嘗試使用以下命令鏈接以下庫: nngpp
mkdir build
cd build
cmake ..
make
make install
但是,在CMakeLists.txt
使用以下內容測試演示或在項目中使用庫時:
...
add_executable(target main.cpp)
target_link_libraries(target nngpp)
我收到以下錯誤:
fatal error: 'nngpp/nngpp.h' file not found
#include <nngpp/nngpp.h>
^~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/rest.dir/rest/server.o] Error 1
make[1]: *** [CMakeFiles/rest.dir/all] Error 2
make: *** [all] Error 2
注意:該庫僅包含標題。 但我不想在我的項目中復制它。
和
find_package(nngpp)
使用庫很簡單:
add_executable(target main.cpp)
target_link_libraries(target nng::nngpp)
這里nng::nngpp
是nng::nngpp
庫,因此它會為您關心包含目錄。
如果沒有更多信息,很難確切地知道出了什么問題。 我建議運行make VERBOSE=1
。 這將向您顯示在嘗試編譯給您錯誤的文件時正在執行的命令行。
在命令行中查看包含標志(例如-I
標志,如果您使用的是gcc
)。 找到nngpp
的目錄並仔細檢查您的頭文件是否在那里,以及相對於該目錄的正確路徑是引用頭文件。 也許你只需要#include <nngpp.h>
代替?
以下工作:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(comm)
set(CMAKE_CXX_STANDARD 11)
find_package(nng REQUIRED)
find_package(Threads)
find_package(nngpp REQUIRED)
add_executable(server src/tfo-server.cpp)
target_link_libraries(server nng::nng nng::nngpp)
這也有效:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(comm)
set(CMAKE_CXX_STANDARD 11)
add_executable(server src/tfo-server.cpp)
include_directories(server /usr/local/include)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.