2

I have the googlebenchmark source code in ~/usr/local and build the whole thing with cmake -DCMAKE_BUILD_TYPE=Release from inside build: cd build; cmake -DCMAKE_BUILD_TYPE=Release; make, and then in my project's CMakeLists.txt I have the following:

set(BENCHMARK_ROOT ~/local/benchmark/build/src)
set(BENCHMARK_INCLUDE_DIR ~/local/benchmark/include)

I would like to keep the library in my home directory, as is shown here, and it works fine with this set-up; my C++ project can see benchmark. However, the warning ***WARNING*** Library was built as DEBUG. Timings may be affected. is still there, so I believe the README.md does not tell the whole story. How to fix this? I even tried with cmake -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON ../ so that it actually downloads googletest and stores it in third_party directory inside build. However, issuing make leads it to an error: it cannot find the googletest it has just built.

EDIT: I've included

if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
    add_definitions(-DNDEBUG)
endif()

into the CMakeLists.txt of benchmark, still the warning persists. The approach has been suggested https://stackoverflow.com/questions/34302265/does-cmake-build-type-release-imply-dndebug

1
  • The error message is about absence of NDEBUG macro definition when compile the project (see e.g. here). Check that the macro is defined in your case. (You may use make VERBOSE=1 for check actual command lines which build your project). CMake defines the macro in Release builds by default, but it depends from your CMakeLists.txt whether this default is applied.
    – Tsyvarev
    Commented Dec 10, 2019 at 21:55

1 Answer 1

0

After including

if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
    add_definitions(-DNDEBUG)
endif()

into benchmark's CMakeLists.txt and re-building it, and linking my executable towards newly built library, voila, here is a sample output:

... { "type": "Unified", "level": 3, "size": 25344000, "num_sharing": 16 } ], "load_avg": [0.4,0.18,0.23], "library_build_type": "release"

Thus, sometimes it makes sense to install the library from sources, in order to build it as Release.

In addition, one does something like

set(BENCHMARK_ROOT ~/local/benchmark/build/src)
target_link_directories(my_executable PUBLIC ${BENCHMARK_ROOT})

after having built the library inside (in my case) ~/local/nechmark/build/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.