unresolved external symbol "class testing::internal::Mutex testing::internal::g_gmock_mutex" error

3,090 views
Skip to first unread message

Roger Li

unread,
Oct 28, 2011, 6:50:29 PM10/28/11
to Google C++ Mocking Framework
Hi,

I am using the the gmock built from trunk. Reason for that is I need
to compile the gmock into DLL and my tests are in DLL code. I saw
there is a check in on trunk to add the ability.

After I build the gmock into DLL it seems to work fine first with the
empty test case. Then when I try to create several mock objects the
linker error shows up for the DLL code:

>Linking...
1> Creating library C:\IPDS\Dev\IPDS.trunk.1.2.5.16010_13_Level_1.svn
\src\..\build\Release\lib\APCO.lib and object C:\IPDS\Dev\IPDS.trunk.
1.2.5.16010_13_Level_1.svn\src\..\build\Release\lib\APCO.exp
1>APPC_ProcedureConfirmationMessageUtility_Test.obj : error LNK2001:
unresolved external symbol "class testing::internal::Mutex
testing::internal::g_gmock_mutex" (?
g_gmock_mutex@internal@testing@@3VMutex@12@A)
1>APPC_ProcedureConfirmationMessageUtility_Test.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)
1>C:\IPDS\Dev\IPDS.trunk.1.2.5.16010_13_Level_1.svn\src\..\bin\Release
\APCO.dll : fatal error LNK1120: 2 unresolved externals

The link error shows as long as I try to create the mock objects in
the code.

Really appreciate your help!

Thanks,
Roger

The following is the code and hope it can help:

// Mock objects for APCO_Command
//
class Mock_PATN_Command : public Commands::APCO_Command
{
public:

// The mock for APCO_Command.isDragOrDrop()
MOCK_CONST_METHOD0(isDragOrDrop, const bool());
};

// Test the creation of Mock_PATN command
//
TEST_F(APPC_ProcedureConfirmationMessageUtilityTest,
TestCreatePATNCommand)
{
// Linker error will gone if this line is commented out.
Mock_PATN_Command * command = new Mock_PATN_Command();
}

Roger Li

unread,
Oct 28, 2011, 7:29:01 PM10/28/11
to Google C++ Mocking Framework
Um... I found I need to add the preprocessor
GTEST_LINKED_AS_SHARED_LIBRARY=1 to the DLL code to export those
methods correctly. But I got a C4275 warning in my DLL code. The
warning is generated at line 158 of gtet-test-part.h:

class GTEST_API_ HasNewFatalFailureHelper
: public TestPartResultReporterInterface {
....

Apparently base class TestPartResultReporterInterface is not DLL
exportable. Can I ignore this warning safely?

Thanks,
Roger

Greg Miller

unread,
Oct 31, 2011, 11:29:42 AM10/31/11
to Roger Li, Google C++ Mocking Framework
Was this from a debug build (/MTd)? If so, you can safely ignore it. More info at http://msdn.microsoft.com/en-us/library/3tdb471s(v=vs.80).aspx

Greg

Roger Li

unread,
Oct 31, 2011, 12:06:10 PM10/31/11
to Google C++ Mocking Framework
Thanks Greg. But I compiled the Mock as the release build (/MD).

Roger

On Oct 31, 8:29 am, Greg Miller <j...@google.com> wrote:
> Was this from a debug build (/MTd)? If so, you can safely ignore it. More
> info athttp://msdn.microsoft.com/en-us/library/3tdb471s(v=vs.80).aspx
Reply all
Reply to author
Forward
0 new messages