2

In ~/install/benchmark, I have checked out Google Benchmark (https://github.com/google/benchmark) and built it in Release mode according to the instructions here.

In ~/personal-projects/benchmarking, I have my own code with a BUILD file and a WORKSPACE file. In the WORKSPACE file, I've got

local_repository(
    name = "com_google_benchmark",
    path = "../../install/benchmark",
)

And in the BUILD file, I have

cc_binary(
    name = "fast_inverse_sqr_root",
    srcs = ["fast_inverse_sqr_root.cpp"],
    deps = [
        "@com_google_benchmark//:benchmark_main",
    ],
)

When I bazel run //fast_inverse_sqr_root, it says: ***WARNING*** Library was built as DEBUG. Timings may be affected.

I've found this related question but that person is using cmake while I'm using Bazel to build my code. I'm not sure what is going on here. Why is it saying the library was built as DEBUG?

bun9
  • 161
  • 8

1 Answers1

1

Try telling Bazel to compile everything in optimized mode: bazel run -c opt //fast_inverse_sqr_root.

Benjamin Peterson
  • 19,297
  • 6
  • 32
  • 39
  • Thanks that worked. Still pretty confused how this happened, if my `WORKSPACE` is referring to a library that was built with Release mode already. It's not like this `bazel run` invocation is re-building that library. Oh well – bun9 May 21 '22 at 17:11
  • 1
    Bazel builds gtest itself. Building it yourself with cmake is not necessary nor relevant to the compiler flags Bazel uses to compile it. – Benjamin Peterson May 22 '22 at 05:12
  • This is Google Benchmark not gtest, unless I'm misunderstanding your comment? – bun9 May 22 '22 at 13:00
  • 1
    Sorry, I meant to say the benchmark library. – Benjamin Peterson May 22 '22 at 17:24