DLL exports

Started by
3 comments, last by the darkening 22 years, 10 months ago
Hi, I want to access a class inside a DLL, but also use it within the DLL. So I have to use "__declspec(dllexport)", no? But VC++ says me (if I try that): error LNK2005 "class ..." already defined in "...". I can avoid this if I use "extern" in the .h file (in which the class is used). But then I can''t reach the class outside of the DLL. Question: How do I avoid LNK2005 but also can use the class in my application ("extern __declspec(dllexport)" doesn''t work!)? Darkening
Advertisement
instead try
  __declspec(dllimport);   


i''m not sure tho......
you should specify __declspec(dllexport) on the class (in the header file) when building the dll, and specify __declspec(dllimport) in the header when using the dll. Easiest is to use a #define.

ex.
        // SomeClass.h// ......#ifndef BUILDING_DLL#define DLL_EXPORT __declspec(dllexport)#else#define DLL_EXPORT __declspec(dllimport)#endifclass DLL_EXPORT SomeClass{    // whatever....};        

And then define BUILDING_DLL only when you are building the DLL.

Edited by - Dactylos on June 27, 2001 5:57:23 PM
Actually it works, but now I get the compiler warning C4273 (something like "Inconsistent DLL binding..." (I don''t know the English text, because I have a German version)). What does THAT mean! VC++ does a dllEXport if I write dllIMport. If I write dllEXport, it gives me nothing but errors. That''s really amazing!

Darkening
@ Daktylos: I can''t build the dll if I use "dllexport". I get about 3 error messages "symbol redefined..."!

This topic is closed to new replies.

Advertisement