building DLLs (was:RE: New user help - dont understand Mount (and the rest))

Kevin Wright kevin@wright.org
Tue Feb 20 16:51:00 GMT 2001


Markus,

I believe I derived that example from Charles Wilson, so he would have more
expertise in this area. However, I can say from my own experience that I
always have to use a two step process:

Here's an example from my notes when I built libiconv:

a) create the .def file using dlltool
   (this creates a libfoo.dll.a which can be linked against.)
   $ dlltool --export-all --output-def libiconv_.def --dllname libiconv.dll
*.o
   NOTE: be careful which .o files are used for this. You don't always want
   to export all of the symbols otherwise you'll have problems creating the
dll.
   A good rule of thumb is to use the same objects that would normally be
   used to create the static library.

b) create the dll using gcc -shared
   $ gcc -shared -Wl,--enable-auto-image-base -o libiconv.dll \
     -Wl,--out-implib=libiconv.dll.a libiconv_.def *.o

c) copy the dll file to /usr/local/bin
d) copy the dll.a file to /usr/local/lib


Here's some notes I have from either email or a README somewhere from
Charles Wilson:

With newer versions of GCC (and Cygwin) you can create DLLs much more easily
without the need for dllhelpers.  You would use something like

   gcc -Wl,--out-implib,libtest.import.a -shared -o test.dll test.o

This would create "test.dll" with from the object file "test.o" .  It will
also create an import library for the DLL (libtest.import.a).

(Of course, you still need to add the prefixes "__declspec(dllexport)" and
"__declspec(dllimport)" to your headers as needed.)


The last piece of info from Charles regarding adding the dllimport and
dllexport
is the most difficult part. I'm still not sure of the best way to do that.

Hope this helps,

--Kevin
> -----Original Message-----
> From: cygwin-owner@sources.redhat.com
> [ mailto:cygwin-owner@sources.redhat.com]On Behalf Of Markus Hoenicka
> Sent: Tuesday, February 20, 2001 4:42 PM
> To: cygwin@cygwin.com
> Subject: building DLLs (was:RE: New user help - dont understand Mount
> (and the rest))
>
>
> Kevin Wright writes:
>  > Here's a way to create dll's in a makefile:
>  >
>  > OBJS=foo
>  > BASE=foo
>  >
>  > gcc -shared -o lib$(BASE).dll -Wl,--out-implib=lib$(BASE).dll.a \
>  >     -Wl,--export-all -Wl,--enable-auto-image-base  \
>  >     -Wl,--output-def=lib$(BASE)_.def $(OBJS)
>  >
>
> Is this some one-size-fits-all solution for all DLL pains on Cygwin?
> I'd be glad if it was, but apparently I'm out of luck. I'm trying to
> compile OpenSP (a SGML parser) using a DLL. Building the DLL works on
> other platforms. I tried your suggestion above, but I get:
>
> mhoenicka@GIRCH19 ~/prog/OpenSP-1.5pre5/lib/.libs
> $ gcc -shared -o libosp.dll -Wl,--out-implib=libosp.dll.a
> -Wl,--export-all -Wl,
> --enable-auto-image-base -Wl,--output-def=libosp_.def ../*.o
> Cannot export _bss_end__: symbol not defined
> Cannot export _bss_start__: symbol not defined
> Cannot export _data_end__: symbol not defined
> Cannot export _data_start__: symbol not defined
> Creating library file: libosp.dll.a
> collect2: ld returned 1 exit status
>
> I've seen some messages about the "symbol not defined" error but none
> of these brought me closer to a dll. Any additional ideas?
>
> regards,
> Markus
> --
> Markus Hoenicka, PhD
> UT Houston Medical School
> Dept. of Integrative Biology and Pharmacology
> 6431 Fannin MSB4.114
> Houston, TX 77030
> (713) 500-6313, -7477
> (713) 500-7444 (fax)
> Markus.Hoenicka@uth.tmc.edu
> http://ourworld.compuserve.com/homepages/hoenicka_markus/
>
>
> --
> Want to unsubscribe from this list?
> Check out: http://cygwin.com/ml/#unsubscribe-simple
>
>


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list