#2309·benchmark

[BUG] Confusing title in docs/platform_specific_build_instructions.md

Author: bnchwormCreated Sep 28, 2026Updated Sep 28, 2026

Describe the bug In the file https://github.com/google/benchmark/blob/main/docs/platform_specific_build_instructions.md, there is a section titled "Building with Visual Studio 2015, 2017 or 2022". The instructions are not specific to Visual Studio, and the heading is therefore misleading.

I am working on Windows 11 25H2 and using the mingw-w64-ucrt-x86_64-toolchain for compilation and linking: gcc 16.1.0, ld 2.46; and ninja 1.13.2 for the build.

I built the library using the tools mentioned above and then tried to run the code from the "Usage" section of the README, linking against the static library build/src/libbenchmark.a.

The code snippet:

cpp
#include <benchmark/benchmark.h>

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

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

BENCHMARK_MAIN();

Compilation:

D:\Projects\cpptest>c++ main.cpp -isystem "D:/Projects/benchmark/include" -L"D:/Projects/benchmark/build/src" -lbenchmark -lpthread -o main.exe
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x66): undefined reference to `__imp__ZN9benchmark5State16StartKeepRunningEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0xed): undefined reference to `__imp__ZN9benchmark5State17FinishKeepRunningEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x198): undefined reference to `__imp__ZN9benchmark5State16StartKeepRunningEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x229): undefined reference to `__imp__ZN9benchmark5State17FinishKeepRunningEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x28f): undefined reference to `__imp__ZN9benchmark23MaybeReenterWithoutASLREiPPc'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x2ca): undefined reference to `__imp__ZN9benchmark16PrintDefaultHelpEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x2df): undefined reference to `__imp__ZN9benchmark10InitializeEPiPPcPFvvE'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x2f1): undefined reference to `__imp__ZN9benchmark27ReportUnrecognizedArgumentsEiPPc'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x305): undefined reference to `__imp__ZN9benchmark22RunSpecifiedBenchmarksEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x30e): undefined reference to `__imp__ZN9benchmark8ShutdownEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x32d): undefined reference to `__imp__ZN9benchmark8internal17InitializeStreamsEv'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x378): undefined reference to `__imp__ZN9benchmark8internal25RegisterBenchmarkInternalESt10unique_ptrINS_9BenchmarkESt14default_deleteIS2_EE'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text+0x3dc): undefined reference to `__imp__ZN9benchmark8internal25RegisterBenchmarkInternalESt10unique_ptrINS_9BenchmarkESt14default_deleteIS2_EE'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text$_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE[_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE]+0x22): undefined reference to `__imp__ZN9benchmark9BenchmarkC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
D:/Programm/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\egor\AppData\Local\Temp\cctoO03V.o:main.cpp:(.text$_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE[_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE]+0x2b): undefined reference to `__imp__ZTVN9benchmark8internal17FunctionBenchmarkE'
collect2.exe: error: ld returned 1 exit status

I was able to fix the error using the solution described in this Stack Overflow post: https://stackoverflow.com/questions/78600881/undefined-references-when-linking-google-benchmark-with-g-on-windows-msys2-u?newreg=d8053eb47e674ea6a805c335e7e46134

I spent a relatively large amount of time troubleshooting this issue because the section heading in https://github.com/google/benchmark/blob/main/docs/platform_specific_build_instructions.md#building-with-visual-studio-2015-2017-or-2022 is misleading and suggests that the instructions are only relevant to Visual Studio.

I think it would be worth mentioning that these instructions are also applicable to mingw-w64-ucrt-x86_64.

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

  • OS: Windows 11 25H2
  • Compiler and version: gcc 16.1.0, ld 2.46

To reproduce Steps to reproduce the behavior:

  1. git clone https://github.com/google/benchmark.git && cd benchmark
  2. do README Installation instruction with -G Ninja when generating the build system with cmake
  3. create file with code snippet from README Basic usage section and try to compile it with command proposed in the same section below/

Expected behavior Successful compilation and linkage

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.