Skip to content

Commit ef7b889

Browse files
committed
docs: Windows link notes apply to MinGW too, not only Visual Studio
The section on shlwapi and BENCHMARK_STATIC_DEFINE was titled for Visual Studio only, so MinGW-w64 users following the README's g++ command hit undefined __imp_ references without finding the fix. Retitle it "Building on Windows", state the two requirements up front, add the MinGW-w64 command line, and point to it from the README. Fixes google#2309
1 parent a5fdacc commit ef7b889

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ $ g++ mybenchmark.cc -std=c++11 -isystem benchmark/include \
193193
-Lbenchmark/build/src -lbenchmark -lpthread -o mybenchmark
194194
```
195195

196+
On Windows, including MinGW-w64, this also needs `-DBENCHMARK_STATIC_DEFINE`
197+
and `-lshlwapi`; see
198+
[Building on Windows](docs/platform_specific_build_instructions.md#building-on-windows).
199+
196200
Alternatively, link against the `benchmark_main` library and remove
197201
`BENCHMARK_MAIN();` above to get the same behavior.
198202

‎docs/platform_specific_build_instructions.md‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,30 @@ On QNX, the pthread library is part of libc and usually included automatically
1515
[`pthread_create()`](https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.lib_ref/topic/p/pthread_create.html)).
1616
There's no separate pthread library to link.
1717

18-
## Building with Visual Studio 2015, 2017 or 2022
18+
## Building on Windows
1919

20-
The `shlwapi` library (`-lshlwapi`) is required to support a call to `CPUInfo` which reads the registry. Either add `shlwapi.lib` under `[ Configuration Properties > Linker > Input ]`, or use the following:
20+
The notes in this section apply to every Windows toolchain, not only to Visual
21+
Studio:
22+
23+
* The `shlwapi` library is required to support a call to `CPUInfo` which reads
24+
the registry.
25+
* When linking against the static library without going through CMake's
26+
`benchmark::benchmark` target, `BENCHMARK_STATIC_DEFINE` must be defined.
27+
Without it the headers declare every symbol as imported from a DLL, and the
28+
link fails with `undefined reference to __imp_...` errors.
29+
30+
### MinGW-w64 (MSYS2) and Clang
31+
32+
Add both to the compile command from the README:
33+
34+
```
35+
$ g++ mybenchmark.cc -std=c++17 -DBENCHMARK_STATIC_DEFINE -isystem benchmark/include \
36+
-Lbenchmark/build/src -lbenchmark -lpthread -lshlwapi -o mybenchmark
37+
```
38+
39+
### Visual Studio 2015, 2017 or 2022
40+
41+
Either add `shlwapi.lib` under `[ Configuration Properties > Linker > Input ]`, or use the following:
2142

2243
```
2344
// Alternatively, can add libraries using linker options.

0 commit comments

Comments
 (0)