[omniORB] Building a DLL

Ulf Stoermer ulf at emi.yamaha.co.jp
Thu Oct 23 12:19:57 BST 2003


Hi Kendall,

> I can't find _OMNIORB_STUB_DLL anywhere in the stub code or anywhere else
> in the omniORB headers, so I don't think it's necessary to define that.  I
> didn't when I created a DLL from the _SK.cc file.

You're quite right, I never checked on this. _OMNIORB_STUB_DLL
is nowhere defined, so it's not needed.

> Can you elaborate on the use of _OMNIORB_NTDLL_IMPORT?  This would be
> needed in hand-written code that I want to include in the stub DLL right?
> If the stub DLL has only the stub code there's nothing that needs
> _OMNIORB_NTDLL_IMPORT added to it right?

Hm, well, yes and no. This is where all the pain comes from.
Unlike GCC the Microsoft compiler by default doesn't export
any symbol. So if one creates one's own DLL there are two
ways of exporting symbols, either via a def file or with the well
known macro __declspec(dllexport).

How to create such a def file for the stub DLL was nicely described
by you, even though there are also other ways of getting there
(I'm too stupid for all that scripting, so I let the linker tell me which
symbols are undefined and generate from the linker output the def file ;-)

Now for the macro. Corresponding to the __declspec(dllexport) macro
there is also the __declspec(dllimport) macro. The intended use is as
follows, in your header file you write something like

  #ifdef MY_EXPORTS
  #define DLL_IMPORTEXPORT __declspec(dllexport)
  #else
  #define DLL_IMPORTEXPORT __declspec(dllimport)
  #endif

And then if one wants to ex/import a class CExample

  class DLL_IMPORTEXPORT CExample;

Then, when building the DLL one simply defines MY_EXPORTS
and the example class will automatically be exported,
no def file is needed.

When building an application that uses that DLL we need
to include the same header file. In this case we don't define
MY_EXPORTS, so DLL_IMPORTEXPORT then is defined
to be __declspec(dllimport) and indicates to the compiler
that we want to import the class.

So this is what _OMNIORB_NTDLL_IMPORT is for, namely
_OMNIORB_NTDLL_IMPORT is defined to be __declspec(dllimport)
(see CORBA_sysdep.h)

So in turn, if USE_stub_in_nt_dll is defined then all the stub
classes will be prefixed with __declspec(dllimport) and indicate
to the compiler that we want to import them. This is why we
have to define USE_stub_in_nt_dll when we want to compile
the application which uses the stub dll.

Now, if you have "handwritten" code in that stub dll then of
course you are free to use the same macro _OMNIORB_NTDLL_IMPORT
on the other hand, I'd rather stick to the intended use of the
macros as shown above. That means for my own code I'd
use my own definitions. The compiler doesn't care if you export
both by def file and at the same time with __delcspec(dllexport).
So using _OMNIORB_NTDLL_IMPORT is a matter of convenience.

Actually, when now thinking about the whole thing it seems to
me that it should be quite easy to provide a patch to Corba_sysdep.h
in order to get rid off the pain with the def file. When I have some time 
I will have a look into it...


>  The brevity of the comment you
> quoted is what I meant by "not well documented".  I believe I figured out
> what it meant, and if I did then I hope my last reply serves as a better

Well, actually the whole thing now boils down to just 2 points:

1. Create and compile your own stub dll and make sure that all
symbols are exported (via def file or otherwise)

2. When compiling an application (or other dll) that uses the stub dll
then give the preprocessor definition Use_stub_in_nt_dll.

That's all.

By the way, in your recipe you say:

>4. Built the DLL I wanted by typing the following link option in the VS
>"Project Option" box of the Link tab in the Project Settings dialog (this
>in VS 5.0, the latest I have):
>      /def:"release\rsidl.def"

VS does the same thing automatically for you if you add the def file
to the project. Menu: Project->Add To Projects->Files...
Also, the def file may be located anywhere, not only in the project directory
(but okay, where else would one put it :-)

Cheers

Ulf


>                                                                                           
>                                                
>                       "Ulf Stoermer"                                                      
>                                                
>                       <ulf at emi.yamaha.co.jp>               To:       "OmniORB" 
> <omniORB-list at omniorb-support.com>                        
>                       Sent by:                             cc:                            
>                                                
>                       omniorb-list-bounces at omniorb-        Fax to:                        
>                                                
>                       support.com                          Subject:  RE: [omniORB] 
> Building a DLL                                        
>                                                                                           
>                                                
>                                                                                           
>                                                
>                       10/21/2003 08:00 PM                                                 
>                                                
>                                                                                           
>                                                
>                                                                                           
>                                                
> 
> 
> 
> 
> Hi,
> 
> in the header file omniORB4/CORBA_sysdep.h I found following
> comment (I guess written by Sai Lai) and it worked for me:
> 
> // To package stubs into dlls:
> //   1. Define the cpp macro _OMNIORB_STUB_DLL when the stub _SK.cc is
> //      compiled.
> //   2. A .def file has to be created to export the symbols in the dll.
> //      The .def file can be generated automatically based on the output
> //      of dumpbin. For an example, look at how the omniORB2 dll is
> created.
> //a
> // To use stubs that has been packaged into dlls:
> //   1. Make sure that the cpp macro USE_stub_in_nt_dll is defined before
> //      the stub header (.hh) is included.
> //
> // Use _OMNIORB_NTDLL_IMPORT to ensure that MSVC++ use the correct linkage
> // for constants and variables exported by a DLL.
> 
> Cheers
> 
> Ulf
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list
> 



More information about the omniORB-list mailing list