googletest icon indicating copy to clipboard operation
googletest copied to clipboard

[Bug]: Failed to build shared lib with Clang20 on Windows

Open T7imal opened this issue 3 months ago • 0 comments
trafficstars

Describe the issue

When setting the cmake variable BUILD_SHARED_LIBS ON, and using Clang as compiler, the building failed:

❯ cmake --build build
[8/8] Linking CXX shared library bin\gmock_main.dll
FAILED: [code=1] bin/gmock_main.dll lib/gmock_main.lib
C:\Windows\system32\cmd.exe /C "cd . && "D:\Program Files\LLVM\bin\clang++.exe" -nostartfiles -nostdlib -D_DLL -D_MT -Xclang --dependent-lib=msvcrt  -fuse-ld=lld-link -shared -o bin\gmock_main.dll  -Xlinker /MANIFEST:EMBED -Xlinker /implib:lib\gmock_main.lib -Xlinker /pdb:bin\gmock_main.pdb -Xlinker /version:1.16 googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj  lib/gmock.lib  lib/gtest.lib  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
lld-link: error: undefined symbol: class testing::internal::Mutex testing::internal::g_gmock_mutex
>>> referenced by googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj:(protected: bool __cdecl testing::internal::ExpectationBase::is_retired(void) const)
>>> referenced by googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj:(protected: void __cdecl testing::internal::ExpectationBase::Retire(void))
>>> referenced by googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj:(protected: bool __cdecl testing::internal::ExpectationBase::IsSatisfied(void) const)
>>> referenced 4 more times
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Steps to reproduce the problem

Ensure you have installed clang correctly, and execute following commands:

cmake -B build -G"Ninja" -DBUILD_SHARED_LIBS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
cmake --build build

What version of GoogleTest are you using?

373af2e3df71599b87a40ce0e37164523849166b

What operating system and version are you using?

Windows 11 24H2 26100.4351

What compiler and version are you using?

❯ clang -v
clang version 20.1.8
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\Program Files\LLVM\bin

What build system are you using?

❯ cmake --version
cmake version 3.31.8

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

Additional context

No response

T7imal avatar Aug 06 '25 15:08 T7imal