From: gunther.ebert@ixos-leipzig.de (Gunther Ebert)
Subject: Re: dll with c++ at Beta 17
16 Dec 1996 08:07:19 -0800
Sender: daemon@cygnus.com
Approved: cygnus.gnu-win32@cygnus.com
Distribution: cygnus
Message-ID: <32B539B5.3003.cygnus.gnu-win32@ixos-leipzig.de>
References: <m0vZXY3-0005CwC@ermail03.btx.dtag.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.0Gold (WinNT; I)
Original-To: Kurt Hohm <Petra.Leonhardt@t-online.de>
Original-Cc: gnu-win32@cygnus.com
Original-Sender: owner-gnu-win32@cygnus.com

Hi,

to build a dll that uses c++ code successfully you have to do
these things:

1) your dll needs an entry point. This is a function
   int WINAPI dllEntry(HANDLE hDll, DWORD reason, LPVOID reserved);
   which is supposed to do some initialization stuff on
   DLL process or thread attach. You cannot create a working dll
   without an entry point. If you don't need any dll initialization
   this function just has to return TRUE.

2) you must tell the linker what your entry point is.

3) you must tell the linker that it has to build a dll.

4) you must call the linker twice because a dll needs
   a relocation section. The first pass creates some relocation
   information and the second pass creates the actual dll.

5) you have to write a .def file that contains all name-mangled
functions
   (but without the leading underscore) which you are going to export

Your linker command lines have to look like

   ld --dll -e _dllEntry@12 -o jnk --base-file dll.base <objects>
<libraries>
   dlltool --dllname foo.dll --base-file dll.base --def foo.def
--output-lib foo.a \
          --output-exp foo.exp
   ld --dll -e _dllEntry@12 -o foo.dll <objects> <libraries> foo.exp
   rm jnk dll.base

Just some comments to your .def file: It is a little bit complicated to
write
a .def file for c++ functions because these functions are name-mangled.
I have
been using successfully this way to create .def files for c++ dlls:

1) add all object files to a temporary library
   ar rc temp.a <objects>
2) create a .def file automatically from the temporary library
   echo EXPORTS > foo.def
   nm temp.a | grep " [TC] " | sed '/ _/s//  /' | awk '{print $3;}' >>
foo.def
3) link the dll as described above


Good luck,
Gunther
-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
