Daniel Elliott

Using google benchmark with homebrew gcc on OSX

Include

First thing that the google benchmark doesn’t do is tell you which include file you need!

#include "benchmark/benchmark.h"

Apple Clang

For the apple clang that comes with xcode you can just use….

Then to download the library, just use ‘brew install google-benchmark’

Then in cmake you can just use

find_package(benchmark)

and then when you link you link with
target_link_libraries(${PROJECT_NAME} benchmark )

 

Homebrew GCC

If you want to use this library with gcc then the one from homebrew wont work. You’ll get errors when you compile.

You can build it yourself. git clone from github and then build with this command line
cmake -DCMAKE_CXX_COMPILER=g++-6 -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_LTO=true

then you can make -8 and make install. Now gcc will compile with the library (make sure to uninstall the brew version).

Leave a Reply

Your email address will not be published. Required fields are marked *