You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Google Mock can be used as a DLL, but the same DLL must contain Google Test as well.
Indeed, when building my software stack on Windows Server 2016, I passed "*:shared=True", and gmock was built as a shared library. However, some tests using gmock were complaining with this error message:
This test program did NOT call ::testing::InitGoogleTest
What seems to happen is that the test executable calls InitGoogleMock() in the gmock library, which in turn calls InitGoogleTest() in the gtest library, which stores the parsed command line arguments in a g_argvs global variable. Calling RUN_ALL_TESTS() in the executable will then call GTestIsInitialized() which tries to read the content of this global variable.
The problem is that the variable that is read is not the same as the one that was filled. They have the same name but are in different address spaces, causing the error message above.
To fix that, if the user wants to build shared libraries:
gtest should be built as static (for gmock use) and shared (for consumers that will use gmock)
gmock should be built as shared (and use the static version of gtest)
I'm not sure conan allows to build both as static and shared, though. So maybe splitting as two separate packages would be needed.
Otherwise, an easier (but less clean) approach would be to only allow static building.
Package Details (Include if Applicable)
Package Name/Version: gtest/1.8.0
Operating System: Windows Server 2016
Compiler+version: VIsual Studio 2017 (MSVC v141)
Steps to reproduce
Build as gmock and gtest as shared, with gmock linked to shared gtest
Create a test program similar to the one below, linked to gtest and gmock:
#include <gtest/gtest.h>
#include <gmock/gmock.h>
int main(int argc, char **argv)
{
::testing::InitGoogleMock(&argc, argv);
int res = RUN_ALL_TESTS();
return res;
}
Check that the program doesn't complain about gtest not being initialized.
The text was updated successfully, but these errors were encountered:
hey @liberforce
I probably misunderstood your issue, do you see an error message if you run code example above with gtest:shared=True? it seems like I am unable to reproduce it
Sorry, not working with conan anymore, I've switched project at work. And this bug may be trickier to trigger than I thought if @SSE4 couldn't reproduce it.
gmock built as a shared library must use static gtest
This is what the GMock README states:
Indeed, when building my software stack on Windows Server 2016, I passed "*:shared=True", and gmock was built as a shared library. However, some tests using gmock were complaining with this error message:
What seems to happen is that the test executable calls
InitGoogleMock()
in the gmock library, which in turn callsInitGoogleTest()
in the gtest library, which stores the parsed command line arguments in ag_argvs
global variable. CallingRUN_ALL_TESTS()
in the executable will then callGTestIsInitialized()
which tries to read the content of this global variable.The problem is that the variable that is read is not the same as the one that was filled. They have the same name but are in different address spaces, causing the error message above.
To fix that, if the user wants to build shared libraries:
I'm not sure conan allows to build both as static and shared, though. So maybe splitting as two separate packages would be needed.
Otherwise, an easier (but less clean) approach would be to only allow static building.
Package Details (Include if Applicable)
Steps to reproduce
The text was updated successfully, but these errors were encountered: