google / google/googletest

Unresolved symbol g_linked_ptr_mutex

Open
#2,297 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

We have a CMake based build in which we `include()` googletest's top-level `CMakeLists.txt` to get gmock, gtest, etc., targets in our build.

We want to build google test/mock as a shared object, so we ensure that `BUILD_SHARED_LIBS` is `ON` before we include `googletest/CMakelists.txt`.

However, this results in an unresolved symbol for `g_linked_ptr_mutex`. The root cause is that when google test is configuring a shared library through the `cxx_library_with_type` function, [it only sets](https://github.com/google/googletest/blob/master/googletest/cmake/internal_utils.cmake#L179) the `INTERFACE` properties on the target when `$` [generator expression](https://cmake.org/cmake/help/v3.2/manual/cmake-generator-expressions.7.html) is true.

This means that in a local build, even though we told google test to build shared objects, it doesn't set the compile interface definitions correctly for clients of that target.

You can work around this locally without editing google test sources by setting this compile definition yourself on clients of google test, or you can do this:

```
set( BUILD_SHARED_LIBS ON )
add_subdirectory( googletest )
foreach( target gmock gmock_main gtest gtest_main )
target_compile_definitions( ${target} INTERFACE GTEST_LINKED_AS_SHARED_LIBRARY=1 )
endforeach()
```

(This doesn't quite work for gmock_main and gtest_main, see following comments.)

Contributor guide

Open the contributing guide

Research direction

Start with googletest/cmake/internal_utils.cmake, especially cxx_library_with_type, and review how the top-level CMakeLists.txt configures gtest and gmock targets when BUILD_SHARED_LIBS is enabled. Confirm that local shared-library consumers receive the required interface definition and that the g_linked_ptr_mutex unresolved-symbol failure is eliminated for gtest, gmock, and their main targets.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.