tags:

views:

268

answers:

3

I would like to know if the export of class ( __declspec(dllexport) in VC++ ) is a kind of standard ( ANSI , ISO , ... )
I would like to know if someone has already try to do the same with intel c++ compiler and gcc ( mingw on windows ) and if it is possible to mix dlls generated from different compilers ( I really doubt that it is possible )

Thx

+6  A: 

No, __declspec is VC++ specific.

One of the reasons that VC++ needs that is by default, DLLs do not expose symbols outside the DLL unless explicitly requested to do that. On Posix, shared objects expose all their (not-static) symbols unless explicitly told to hide them.

Update

Based on your comment that you want to make your code portable, you want to use the preprocessor and do something like this:

#ifdef WIN32
  #ifdef EXPORT_CLASS_FOO
    #define CLASS_FOO __declspec(dllexport)
  #else
    #define CLASS_FOO __declspec(dllimport) 
  #endif
#else
  #define CLASS_FOO
#endif

class CLASS_Foo foo
{ ... };

In the project that is implementing the class, make sure to add EXPORT_CLASS_FOO as a preprocessor definition (found in Project | NAME Properties.. under C/C++ | Preprocessor | Preprocess Definitions). This way, you'll export them when building the DLL, import them when you are using the DLL and do nothing special under Unix.

R Samuel Klatchko
does it mean that we can export a class and reuse it straight away? Is it system specific ( POSIX ) or compiler ( does intel c++ on linux provide the same behaviour )
It depends on compiler flags on Intel C++ or gcc, but defaults to exposing symbols. Just make some preprocessor macros so you can have that sort of export conditionally compiled.
Andrew McGregor
+1  A: 

Anything that starts with __ in C++ is a vendor-specific extension. I don't know if any other compiler vendors support this, but it most certainly is not compatible cross-compiler.

Dark Falcon
+1, though I do believe MinGW supports this particular Microsoft extension, to make porting code easier. Unlike VC++, MinGW doesn't need it.
Warren Young
+1  A: 

The notion of DLL is very platform-specific. It is not covered by any even remotely universally applicable standard. If fact, the acronym DLL itself is usually reserved for Windows dynamic libraries. Needless to add, anything specific to DLL support in C/C++ is very platform/vendor dependent.

AndreyT
Actually OS2 used DLLs too. But it was shared code between MS and IBM at one time... :-)
Jason D