--- dll.sgml-orig 2002-10-15 22:48:29.000000000 -0500
+++ dll.sgml 2002-10-15 23:31:47.000000000 -0500
@@ -39,19 +39,18 @@ For this example, we'll use a single fil
mydll.c for the contents of the dll
(mydll.dll).
-Now compile everything to objects:
-
-gcc -c myprog.c
-gcc -c mydll.c
-
Fortunately, with the latest gcc and binutils the process for building a dll
is now pretty simple. Say you want to build this minimal function in mydll.c:
-int WINAPI
-mydll_init(HANDLE h, DWORD reason, void *foo)
+
+#include <stdio.h>
+
+int
+hello()
{
- return 1;
-}
+ printf ("Hello World!\n");
+}
+
First compile mydll.c to object code:
@@ -61,7 +60,26 @@ mydll_init(HANDLE h, DWORD reason, void
gcc -shared -o mydll.dll mydll.o
-That's it! However, if you are building a dll as an export library,
+
+That's it! To finish up the example, you can now link to the
+dll with a simple program:
+
+
+
+int
+main ()
+{
+ hello ();
+}
+
+
+
+Then link to your dll with a command like:
+
+
+gcc -o myprog myprog.ca -L./ -lmydll
+
+However, if you are building a dll as an export library,
you will probably want to use the complete syntax:
gcc -shared -o cyg${module}.dll \
@@ -80,9 +98,10 @@ link against, e.g '-lpng -lz -L/usr/loca
Linking Against DLLs
If you have an existing DLL already, you need to build a
-Cygwin-compatible import library (The supplied ones should work, but
-you might not have them) to link against. Unfortunately, there is not
-yet any tool to do this automatically. However, you can get most of
+Cygwin-compatible import library. If you have the source to compile
+the DLL, see for details on having
+gcc build one for you. If you do not have the
+source or a supplied working import library, you can get most of
the way by creating a .def file with these commands (you might need to
do this in bash for the quoting to work
correctly):