1

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
MJeremy
  • 1,102
  • 17
  • 27
  • I assume it put the headers in `/usr/local/include` and you don't have that path in your compilers include directories. – drescherjm Feb 09 '21 at 14:06
  • @drescherjm yes, inside the folder I have the folder `benmark`, how can I include it? – MJeremy Feb 09 '21 at 14:09
  • That would be some setting you need to change in XCode. I don't use that IDE so I can't tell you were the setting is. – drescherjm Feb 09 '21 at 14:10
  • Here is an old question on how to add the include path in XCode: [https://stackoverflow.com/questions/14134064/how-to-set-include-path-in-xcode-project](https://stackoverflow.com/questions/14134064/how-to-set-include-path-in-xcode-project) – drescherjm Feb 09 '21 at 14:11
  • 1
    This question can probably help you: https://stackoverflow.com/questions/445815/linking-libraries-in-xcode – JoaoCostaIFG Feb 09 '21 at 14:21
  • I expect that @MJeremy was not using CMake for the xcode project but I could be wrong. – drescherjm Feb 09 '21 at 14:24
  • Hi, I am not using CMake – MJeremy Feb 09 '21 at 14:25
  • At least type what is actual problem? `still no go` is not explanation of error message! Can't find include file? Linking issue? [ask] – Marek R Feb 09 '21 at 14:26
  • I don't think the proposed duplicate helps with the include path. I believe the problem is can't find the header. – drescherjm Feb 09 '21 at 14:26
  • @MarekR thanks for the prompt response, error msg is updated. I am actually clueless of the nature that's why I posted. BUT now as drescherjm suggested, I guess it would be the lib path is not included in the XCode? – MJeremy Feb 09 '21 at 14:33
  • After update it is clear that JoaoCostaIFG comment (voted up) is a correct solution. – Marek R Feb 09 '21 at 15:13
  • Now you have to actually tell xcode to link to the libraries. – drescherjm Feb 09 '21 at 19:54

2 Answers2

1

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

MJeremy
  • 1,102
  • 17
  • 27
0

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

Marek R
  • 32,568
  • 6
  • 55
  • 140