google / benchmark

A microbenchmark support library
Apache License 2.0
8.6k stars 1.57k forks source link

[BUG] Not able to benchmark on MacOS M1 laptop (compilation error) #1693

Closed david-alvarez-rosa closed 8 months ago

david-alvarez-rosa commented 8 months ago

Describe the bug I'm not able to use the library in M1 MacOS laptop after system-wide installation.

System Which OS, compiler, and compiler version are you using:

To reproduce Steps to reproduce the behavior:

  1. Clone repo
  2. Build library
  3. Run tests (all passing)
  4. Install library globally
  5. Use dummy testing program from README
    
    #include <benchmark/benchmark.h>

static void BMStringCreation(benchmark::State& state) { for (auto : state) std::string empty_string; } // Register the function as a benchmark BENCHMARK(BM_StringCreation);

// Define another benchmark static void BMStringCopy(benchmark::State& state) { std::string x = "hello"; for (auto : state) std::string copy(x); } BENCHMARK(BM_StringCopy);

BENCHMARK_MAIN();

7. Try to compile with 
```prompt
❯ clang++ main.cpp -std=c++11 -lbenchmark -lpthread  

Expected behavior Expected behavior is successful compilation.

Actual result When compiling I'm getting the following error

❯ clang++ main.cpp -std=c++11 -lbenchmark -lpthread  
ld: warning: object file (/usr/local/lib/libbenchmark.a[2](benchmark.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[3](benchmark_api_internal.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[4](benchmark_name.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[5](benchmark_register.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[6](benchmark_runner.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[8](colorprint.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[9](commandlineflags.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[10](complexity.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[11](console_reporter.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[12](counter.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[13](csv_reporter.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[14](json_reporter.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[15](perf_counters.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[16](reporter.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[17](statistics.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[18](string_util.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[19](sysinfo.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)
ld: warning: object file (/usr/local/lib/libbenchmark.a[20](timers.cc.o)) was built for newer 'macOS' version (13.6) than being linked (13.0)

Additional context Nope.

dmah42 commented 8 months ago

what version of macOS are you running?

it looks a lot like the the dummy program was compiled before an upgrade, and the library after the upgrade. i can't see immediately how this is related to the benchmark library as this is an OS level relating to different on-device frameworks/system libraries.

david-alvarez-rosa commented 8 months ago

I'm ussing MacOS Ventura 13.6.

❯ uname -v 
Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000

I did both things (compiling the library, and compiling the dummy program) the same afternoon (within a couple of hours). I was learning on how to use Google's benchmark for C++.

dmah42 commented 8 months ago

did you build the library with CMake? i wonder if you have both system frameworks installed and cmake picks the newest while raw clang++ picks the older...

david-alvarez-rosa commented 8 months ago

Indeed @dmah42, thank you very much. Compiling the dummy program also by using CMake solved the issue!