skip to Main Content

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

#include <benchmark/benchmark.h>

as shown in the instruction still no go with error

'benchmark/benchmark.h' file not found

SO is there any step that is missing?

In /usr/local/lib I have:

libbenchmark.a
libbenchmark_main.a

And in /usr/local/include I have:

benchmark

I am not using CMake for my XCode project.

————– Segmentation ————

After digging on the question here.

I added this /usr/local/include into the Header Search Paths as following.

enter image description here

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

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for the many helps, I have finally figured it out.

    Go to build settings in Xcode and add both header and library search path

    enter image description here

    And then go to linking, add linkers, for my case it looks like this

    enter image description here


  2. Assuming your project uses cmake too, your CMakeLists.txt should contain something like this:

    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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search