[OpendTect_Developers] mClass on Windows

Nanne Hemstra nanne.hemstra at dgbes.com
Thu Dec 1 20:19:23 CET 2011


All,

I'd like to share the reply from John Watson (ARK CLS) with you regarding
the usage of the mClass macro.

<start>

I have never used mClass in our plugins (as was originally suggested when
the macro was introduced) because, while I can see it will evaluate to
"__declspec(dllexport)", I have never worked out how it can evaluate to
"__declspec(dllimport)", and of course both are needed in specific
situations. Our solution is that for every dll that we build (eg.
ClsGen.dll) we have a macro based on the dll name eg. CLSGEN_IMPEXP that
evaluates to either "__declspec(dllimport)" or
"__declspec(dllexport)" depending on whether we are building or calling the
library. We then use CLSGEN_IMPEXP in the declaration of any function or
class that we wish to export from that dll. We use a macro name that
depends on the dll name as one dll will depend on another, so when
compiling any given file, the macro for the dll we are building will
evaluate to  "__declspec(dllexport)" and all others to
"__declspec(dllimport)". Obviously on linux the macro will be empty.

As any dll might have multiple public header files, the logic that sets
CLSGEN_IMPEXP must be in its own header so it can be included by all the
other headers. Our convention to have an ImpExp.h file for every dll
(eg ClsGenImpExp.h),
and every other header of that dll can include it. This switches the
devinition of CLSGEN_IMPEXP based on the operating system and also
CLSGEN_EXPORTS - a macro that is defined by Visual Studio by default for
each dll it builds. Hence the contents of ClsGenImpExp.h looks something
like:

#pragma once
#ifndef CLSGENIMPEXP_H
#define CLSGENIMPEXP_H

/* Header to deal with dll import/export declarations required by MS Visual
Studio compilers */

#if (defined (WIN32) || defined (WIN64)) && !defined (__CYGWIN__) &&
!defined (__MINGW32__)
#  ifdef CLSGEN_EXPORTS
/*   Here we're building the library, so must mark things to be exported
from the library */
#    define CLSGEN_IMPEXP __declspec(dllexport)
#  else
/*   Here we're calling the library, so must mark things to be imported
from the library */
#    define CLSGEN_IMPEXP __declspec(dllimport)
#  endif
#else
/* Here were using a compiler that works such things out for itself */
#  define CLSGEN_IMPEXP
#endif

#endif /* CLSGENIMPEXP_H */


<end>



Best regards,
Nanne



-- 
Nanne Hemstra
Executive Vice President - Americas

dGB Earth Sciences
1, Sugar Creek Center Blvd - Suite 935
Sugar Land, TX 77478 - USA
Phone: +1 281-240-3939, Fax: +1 281-240-3944
http://www.dgbes.com , http://www.opendtect.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20111201/ab15a021/attachment.html>


More information about the Developers mailing list