google / google/googletest

"unresolved external symbol" using FLAGS_gtest_death_test_style on MS Windows

Open
#3,554 4 comments 2 reactions 1 assignee Claimed by @derekmauro View on GitHub
bug
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

**Describe the bug**
I add `GTEST_FLAG_SET(death_test_style, "threadsafe");` to `main()` of a gtest as shown at [Death Test Styles](https://google.github.io/googletest/advanced.html#death-test-styles):

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
GTEST_FLAG_SET(death_test_style, "threadsafe");
return RUN_ALL_TESTS();
}

This compiles on Linux (Debian Bullseye) without any errors. On Microsoft Windows I get:

test_UpnpString.obj : error LNK2019: unresolved external symbol "class std::basic_string,class std::allocator > testing::FLAGS_gtest_death_test_style" (?FLAGS_gtest_death_test_style@testing@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) referenced in function main [C:\Users\ingo\devel\upnplib-dev\upnplib\gtests\build\test_UpnpStri
ng_old.vcxproj]
C:\Users\ingo\devel\upnplib-dev\upnplib\gtests\build\Release\test_UpnpString_old.exe : fatal error LNK1120: 1 unresolved externals
[C:\Users\ingo\devel\upnplib-dev\upnplib\gtests\build\test_UpnpString_old.vcxproj]

I expect it to compiles without errors, like it does on Linux.

**Steps to reproduce the bug**
On MS Windows 10 add the line `GTEST_FLAG_SET(death_test_style, "threadsafe");` to `main()` as shown above to an existing gtest that compiles before without errors.

**Does the bug persist in the most recent commit?**
Yes.

**What operating system and version are you using?**
i use Microsoft Windows 10 with Microsoft Visual Studio 2019 Community version and selected the default development command line environment

ingo@WIN10-DEVEL C:\Users\ingo> "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.9.5
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

as described at https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-160#use-the-developer-tools-in-an-existing-command-window

**What compiler and version are you using?**

PS> cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29915 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

**What build system are you using?**

PS> cmake --version
cmake version 3.19.20122902-MSVC_2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.