[英]How to include an open source library into C++ project?
I am trying to use an open-source library into my project, specifically this one here .我正在尝试在我的项目中使用一个开源库,特别是这里的这个。
I have followed the installation guidelines and installed it globally with我已遵循安装指南并在全球范围内安装了它
sudo cmake --build "build" --config Release --target install
And I could see that the library is installed in /usr/local/lib
, now back to my own C++ code, when I tried to我可以看到该库安装在/usr/local/lib
中,现在回到我自己的 C++ 代码
#include <benchmark/benchmark.h>
as shown in the instruction still no go with error如指令所示仍然没有 go 错误
'benchmark/benchmark.h' file not found
SO is there any step that is missing?那么是否缺少任何步骤?
In /usr/local/lib
I have:在/usr/local/lib
我有:
libbenchmark.a
libbenchmark_main.a
And in /usr/local/include
I have:在/usr/local/include
我有:
benchmark
I am not using CMake for my XCode project.我没有在我的 XCode 项目中使用 CMake。
-------------- Segmentation ------------ -------------- 分割 ------------
After digging on the question here.在挖掘了这里的问题之后。
I added this /usr/local/include
into the Header Search Paths
as following.我将此/usr/local/include
到Header Search Paths
中,如下所示。
And then I tried然后我尝试了
#include "benchmark/benchmark.h" // I tried <benchmark/benchmark.h> as well
But this resulted in a direct build failure with error但这导致直接构建失败并出现错误
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
Assuming your project uses cmake
too, your CMakeLists.txt
should contain something like this:假设您的项目也使用cmake
,您的CMakeLists.txt
应该包含如下内容:
find_package(benchmark REQUIRED)
add_executable(YouLibBenchamrkTarget sources1.cpp ...)
target_link_libraries(YouLibBenchamrkTarget YourLibraryTarget benchmark::benchmark)
This should resolve problems with include and linking issues (you didn't specified actual nature of your problem).这应该解决包含和链接问题的问题(您没有指定问题的实际性质)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.