Small problem with virtual function in DLL class...
-
Hi everyone, I have class A in DLL with virtual function in it, like this...
class __declspec(dllexport) A { public: vitual void Foo() { some code; }; }
And there is derived class B in the same DLL...class __declspec(dllexport) B : public A { public: vitual void Foo() { some code; }; }
Now, when I compile it, everything's ok. But I also have a console app where I create instances of class B from DLL. Of course I link .lib file with it. But when I try to compile this app I have an error from linker. error LNK2001: unresolved external symbol "public: virtual void __thiscall B::Foo(void)" Does anybody have any ideas how to solve this matter? P.S. When I check EXPORTS from my DLL with dumpbin.exe, I can see both methods there. So, ?FooA@A@@ and ?FooA@B@@ are there. But linker's looking for ?Foo@B@@, without "A" at the end of the method name and obviously can't find it. Any idea what's wrong? Thanks in advance, va'Lery -
Hi everyone, I have class A in DLL with virtual function in it, like this...
class __declspec(dllexport) A { public: vitual void Foo() { some code; }; }
And there is derived class B in the same DLL...class __declspec(dllexport) B : public A { public: vitual void Foo() { some code; }; }
Now, when I compile it, everything's ok. But I also have a console app where I create instances of class B from DLL. Of course I link .lib file with it. But when I try to compile this app I have an error from linker. error LNK2001: unresolved external symbol "public: virtual void __thiscall B::Foo(void)" Does anybody have any ideas how to solve this matter? P.S. When I check EXPORTS from my DLL with dumpbin.exe, I can see both methods there. So, ?FooA@A@@ and ?FooA@B@@ are there. But linker's looking for ?Foo@B@@, without "A" at the end of the method name and obviously can't find it. Any idea what's wrong? Thanks in advance, va'LeryThis is, I admit, a guess. When included by the application, is it marked
__declspec(dllimport)
? You should normally write your header as follows:#ifdef BUILDING_DLL
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif // def BUILDING_DLLclass MYDLL_API A { /* declarations omitted */ };
class MYDLL_API B : public A { /* declarations omitted */ };and define BUILDING_DLL in the DLL project. I'm not sure how well
__declspec(dllexport)
interacts with in-line member function definitions. -
This is, I admit, a guess. When included by the application, is it marked
__declspec(dllimport)
? You should normally write your header as follows:#ifdef BUILDING_DLL
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif // def BUILDING_DLLclass MYDLL_API A { /* declarations omitted */ };
class MYDLL_API B : public A { /* declarations omitted */ };and define BUILDING_DLL in the DLL project. I'm not sure how well
__declspec(dllexport)
interacts with in-line member function definitions.