I'm having a linking problem when compiling a class, derived from an interface from another DLL. This is the code. I have an c++ interface (abstract class), specified in DLL like this:
// ============================ Source DLL
// header IFace.h"
#ifdef MY_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
class MY_API IFace
{
public:
virtual ~IFace() {};
virtual bool Foo() = 0;
};
// ============================ My DLL
// header
#ifdef MY_EXPORTS22
#define MY_API22 __declspec(dllexport)
#else
#define MY_API22 __declspec(dllimport)
#endif
#include "IFace.h"
class MY_API22 MyClass_Mock : public IFace
{
// IFace
public:
virtual ~MyClass_Mock() {};
virtual bool Foo() ;
};
// cpp file
bool MyClass_Mock::Foo()
{
return true;
}
When I compile my DLL, which implements the interface IFace, I get the linker error:
- error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl IFace::IFace(void)"
- error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl IFace::IFace(class IFace const &)"
- error LNK2019: unresolved external symbol "__declspec(dllimport) public: class IFace & __cdecl IFace::operator=(class IFace const &)"
- error LNK2001: unresolved external symbol "__declspec(dllimport) public: class IFace & __cdecl IFace::operator=(class IFace const &)"
When I explicitly define (or delete in C++11) copy ctor and assignment operator, I still have have errors for default ctor and dtor.
I don't want to link against .lib file for the source DLL as I want to load it dynamically later through LoadLibrary. How can I fix this linking problem?
__interface
keyword instead. Added for this reason. – Hans Passant