Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gmock built as a shared library must use statically linked gtest #335

Closed
liberforce opened this issue Jun 26, 2018 · 3 comments
Closed

gmock built as a shared library must use statically linked gtest #335

liberforce opened this issue Jun 26, 2018 · 3 comments
Assignees
Labels

Comments

@liberforce
Copy link

liberforce commented Jun 26, 2018

gmock built as a shared library must use static gtest

This is what the GMock README states:

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

  1. Build as gmock and gtest as shared, with gmock linked to shared gtest
  2. 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;
}
  1. Check that the program doesn't complain about gtest not being initialized.
@SSE4 SSE4 self-assigned this Jun 28, 2018
@SSE4 SSE4 added the bug label Jun 28, 2018
@SSE4
Copy link
Member

SSE4 commented Jun 28, 2018

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

@SSE4 SSE4 added this to in progress in Test & Mock frameworks Aug 5, 2018
@solvingj
Copy link
Member

@liberforce if you still have issue, can you let us know so we can reopen this?

@liberforce
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

No branches or pull requests

3 participants