Fix ODR violation of gtest global variables in gmock #1059
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When both gtest and gmock are DSOs configured by cmake, and are dynamically
linked into a program, the program crashes with a double free error upon exit,
if the test program is invoked with at least one gtest flag specified,
or if there is a death test in the program. This is due to ODR violation
of global
std::string
variables (holding command line arguments) defined ingtest but duplicated in gmock, because gtest is linked into gmock.
This updates cmake configuration for gmock to remove gtest from gmock
libraries. Notice that the gmock configure script also doesn't link gtest into gmock.
This also removes gmock from gmock_main to be consistent with gtest and
gtest_main.
Tested by running googletest unit tests as well by running tests in a
larger codebase that uses googletest (both DSO and .a) as a testing framework
on a linux system with gcc-4.9 and gcc-5.4.
Potentially also fixes some bugs mentioned in #930