[英]How to include an open source library into C++ project?
我正在嘗試在我的項目中使用一個開源庫,特別是這里的這個。
我已遵循安裝指南並在全球范圍內安裝了它
sudo cmake --build "build" --config Release --target install
我可以看到該庫安裝在/usr/local/lib
中,現在回到我自己的 C++ 代碼
#include <benchmark/benchmark.h>
如指令所示仍然沒有 go 錯誤
'benchmark/benchmark.h' file not found
那么是否缺少任何步驟?
在/usr/local/lib
我有:
libbenchmark.a
libbenchmark_main.a
在/usr/local/include
我有:
benchmark
我沒有在我的 XCode 項目中使用 CMake。
-------------- 分割 ------------
在挖掘了這里的問題之后。
我將此/usr/local/include
到Header Search Paths
中,如下所示。
然后我嘗試了
#include "benchmark/benchmark.h" // I tried <benchmark/benchmark.h> as well
但這導致直接構建失敗並出現錯誤
Undefined symbols for architecture x86_64:
"benchmark::internal::InitializeStreams()", referenced from:
___cxx_global_var_init in main.o
ld: symbol(s) not found for architecture x86_64
假設您的項目也使用cmake
,您的CMakeLists.txt
應該包含如下內容:
find_package(benchmark REQUIRED)
add_executable(YouLibBenchamrkTarget sources1.cpp ...)
target_link_libraries(YouLibBenchamrkTarget YourLibraryTarget benchmark::benchmark)
這應該解決包含和鏈接問題的問題(您沒有指定問題的實際性質)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.