Hi,
I been looking for some time now, and failed to find the information
about this issue:
http://groups.google.com/group/googlemock/browse_thread/thread/a68996453749a230/4ec464cefdc0edf8?lnk=gst&q=g_gmock_mutex#4ec464cefdc0edf8
it seemed the solution was to include the
GTEST_LINKED_AS_SHARED_LIBRARY=1 to the dll code to export the methods
correctly. However for me it failed to solve the problem.
This is what i've done:
1. SVN checkout, External at revision 605, At revision 404. In Cygwin
in windows 7
2. with cmake version 2.8.7, generate sln files for gmock in directory
build.
3. Run Visual studio 2010 and configure gtest and gmock projects in
the following way:
. Change configuration to dll, and change extension
. Change Runtime Library to Multi-threaded Debug DLL (/MDd), to be
inline with my test project
. add preprocessor flag GTEST_CREATE_SHARED_LIBRARY=1 to both
projects, additionally to this the following values were defined:
gmock - WIN32 _WINDOWS _DEBUG _UNICODE UNICODE _WIN32 STRICT
WIN32_LEAN_AND_MEAN GTEST_HAS_PTHREAD=0 _HAS_EXCEPTIONS=1
CMAKE_INTDIR="Debug" _ITERATOR_DEBUG_LEVEL=0
GTEST_CREATE_SHARED_LIBRARY=1
gtest - WIN32 _WINDOWS _ITERATOR_DEBUG_LEVEL=0 _DEBUG _UNICODE
UNICODE _WIN32 STRICT WIN32_LEAN_AND_MEAN GTEST_HAS_PTHREAD=0
_HAS_EXCEPTIONS=1 CMAKE_INTDIR="Debug" GTEST_CREATE_SHARED_LIBRARY=1
4. Compile, this creates gtest.dll, gtest.lib, gtest.pdb, gmock.dll,
gmock.lib and gmock.pdb.
5. My project has several static libraries that are used to create a
main dll. Each of these static libs have several tests defined. What i
do now is in one of these static libraries defined a
"googletest" (there are already cppunit tests defined there). I link
also against the lib files created above. In this step i do not set
the GTEST_LINKED_AS_SHARED_LIBRARY, since this makes my library fails
to compile with loads of: warnings like: needs to have dll-interface
to be used by clients of class 'testing::internal::ExpectationBase'.
All the methods that are exported from the DLL are throwing warnings.
6. Create a test executable and reference the main DLL. Define the
PullInMyLibrary dummy functions in both test dll and test exe.
This is my main:
::testing::InitGoogleMock(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
7. This compiles without any problem. Im able to add new tests and run
them. This also proves that im using google mock that is in the
library.
Now i want to add a mock, so in the same source file ive created the
dummy mock:
class Turtle {
public:
virtual ~Turtle() {}
virtual void PenUp() = 0;
virtual void PenDown() = 0;
virtual void Forward(int distance) = 0;
virtual void Turn(int degrees) = 0;
virtual void GoTo(int x, int y) = 0;
virtual int GetX() const = 0;
virtual int GetY() const = 0;
};
class MockTurtle : public Turtle {
public:
MOCK_METHOD0(PenUp, void());
MOCK_METHOD0(PenDown, void());
MOCK_METHOD1(Forward, void(int distance));
MOCK_METHOD1(Turn, void(int degrees));
MOCK_METHOD2(GoTo, void(int x, int y));
MOCK_CONST_METHOD0(GetX, int());
MOCK_CONST_METHOD0(GetY, int());
};
Now add to the test method MockTurtle Mock;
And ups, get the same link errors as the discussion above.
.obj) : error LNK2001: unresolved external symbol "class
testing::internal::Mutex testing::internal::g_gmock_mutex" (?
g_gmock_mutex@internal@testing@@3VMutex@12@A)
.obj) : error LNK2001: unresolved external symbol "class
testing::internal::Mutex testing::internal::g_linked_ptr_mutex" (?
g_linked_ptr_mutex@internal@testing@@3VMutex@12@A)
Ive exported the functions from the dll and they are present in both
DLLs. This is the exported report:
gmock.dll
class testing::internal::Mutex testing::internal::g_gmock_mutex
0x100aa704 0x000aa704 500 (0x1f4) gmock.dll C:\GMOCK\googlemock-read-
only\build\Debug\gmock.dll Exported Function
class testing::internal::Mutex testing::internal::g_linked_ptr_mutex
0x100aa657 0x000aa657 503 (0x1f7) gmock.dll C:\GMOCK\googlemock-read-
only\build\Debug\gmock.dll Exported Function
gtest.dll
class testing::internal::Mutex testing::internal::g_linked_ptr_mutex
0x1008ffd7 0x0008ffd7 370 (0x172) gtest.dll C:\GMOCK\googlemock-read-
only\build\gtest\Debug\gtest.dll Exported Function
Why doesn't the g_linked_ptr_mutex complains when only gtest are
defined.
Im struggling with this one, hope someone can help me.
Thank you
Jorge Costa