mat007 / turtle

C++ mock object library for Boost

Home Page:http://turtle.sourceforge.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linker error when using an abstract base class (Vs2010, VS2012)

beetleb opened this issue · comments

I cannot seem to set up a mock of an abstract base class. Below is the code:

In the header file:

class ABCD { public: virtual ~ABCD(); virtual int AMethod() = 0; virtual double BMethod() = 0; };

In the cpp file:

ABCD::~ABCD() { }

In the test file:

`
MOCK_BASE_CLASS(MockABCD, ABCD)
{
MOCK_METHOD(AMethod,0)
MOCK_METHOD(BMethod,0)
};

BOOST_AUTO_TEST_CASE( some_test )
{
MockABCD abcd;
BOOST_CHECK_EQUAL(1.0, 1.0);
}
`

This works if ABCD is not an abstract class.

The linker error I get is:

Creating library ..\..\..\..\lib_debug\BOOSTUnitTests.lib and object ..\..\..\..\lib_debug\BOOSTUnitTests.exp fact_unit_tests.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl ABCD::~ABCD(void)" (??1ABCD@@UEAA@XZ) referenced in function "intpublic: __cdecl MockABCD::MockABCD(void)'::1'::dtor$0" (?dtor$0@?0???0MockABCD@@QEAA@XZ@4HA) ..\..\..\..\lib_debug\BOOSTUnitTests.exe : fatal error LNK1120: 1 unresolved externals

I think it is trying to say that MockABCD is trying to call the destructor of ABCD and it cannot find it. However, I have explicitly defined the destructor in the CPP file. I even tried setting a pragma in Visual Studio to ensure it is not inlined.

Using Turtle version 1.3

Hi,

I just tried it with the ABCD.cpp file in the same project as the test and it does build correctly.
Are you sure you link against the code for ABCD?
Do you have it in a separate library?

Hi,

Did you try it with Visual Studio?

I'll check the project settings when I go to work, but I will point out that if instead of ABCD I inherit from a concrete class defined in the same files, it builds just fine. I assume that rules out invalid project settings?

TurtleIssue.zip

I've attached my solution (zipped).

Thanks.

In release configuration you have set TurtleIssue to be an application (see properties configuration general). In debug configuration it's a DLL but nothing is exported.
Set everything as library instead.

Then just as I suspected TurtleIssueUnitTests does not link against TurtleIssue, go to properties / common properties / framework and referencies then click add new reference and add TurtleIssue.

With those two modifications it links fine.

I did not set up the Release Configuration - this was just a toy example to send to you - should have told you to look only on Debug.

You're right about not exporting it - that's probably highly relevant. As for linking, I think I may have done it on my "real" solution/project. When I go back to work I'll check for these. I just found it strange that it worked if ABCD is not abstract.

Thanks.

It worked after making the changes.