From: Greg C. <chi...@mi...> - 2003-10-02 15:38:27
|
[problems exporting member functions from a dll] Jeff Williams wrote: > > I looked closer at the problem, and it seems that for some reason all my class functions are not being exported. > > In some classes, non of the non virtual funcs are exported at all, and they are not inline. Even in those cases their are a few virtual funcs that are not exported either. > > Is this a linker bug? Probably not. I don't remember ever seeing a problem like this that couldn't be resolved by changing the code or the command lines. > I'm using version: > GNU ld version 2.14.90 20030807 > > Also, I am curious, when using __declspec(dllexport), and you forward declare a class that will be exported, does the forward declare need the __declspec? > > ie: class __declspec(dllexport) myclass; I don't really know. I always code the export or import declspec everywhere, even for forward declarations, and it always works. I write the declspec explicitly only once, in macros defined in one header as in this message: http://article.gmane.org/gmane.comp.gnu.mingw.user/4170/ and then I include that header wherever needed, just to make it harder to get it wrong. As long as you define the right macro on each compiler command line, it ought to work every time. Examples using the macros in that message: In your code, I believe you need a macro on every declaration only--including declarations that are also definitions: Class definition (which is also a declaration): class MY_PROJECT_NAME_EXPIMP foo{...}; Class forward declaration: class MY_PROJECT_NAME_EXPIMP foo; Non-member function--prototype: bool MY_PROJECT_NAME_EXPIMP bar(); Non-member function--definition: bool bar(); // Prototype used macro--don't need it here too. Command lines: g++ -DMY_PROJECT_NAME_BUILD_DLL [etc.] # build dll g++ -DMY_PROJECT_NAME_USE_DLL [etc.] # build exe |