Mail Archives: cygwin/1996/12/16/08:07:19
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 AT 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 AT 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 AT cygnus DOT com" with one line of text: "help".
- Raw text -