delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/03/25/18:14:03

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Tue, 26 Mar 2002 00:12:48 +0100
From: "Gerrit P. Haase" <gp AT familiehaase DOT de>
Organization: Esse keine toten Tiere
X-Priority: 3 (Normal)
Message-ID: <125478376749.20020326001248@familiehaase.de>
To: Wiebe de Vries <w DOT devries AT pecoma DOT nl>
CC: cygwin AT cygwin DOT com
Subject: Re: Shared libraries.
In-Reply-To: <888E9ABB4271D311B3B20008C7B3C8FC393A77@pecasm02.pecoma.nl>
References: <888E9ABB4271D311B3B20008C7B3C8FC393A77 AT pecasm02 DOT pecoma DOT nl>
MIME-Version: 1.0

Hallo Wiebe,

Am 2002-03-25 um 16:12 schriebst du:

> I'm trying to build and use shared libraries with Cygwin under Windows 2000.
> The first step, i.e. building the library, succeeds. I get a libmylib.so
> (together with libmylib.so.1 and limmylib.so.1.0.0). However, linking is a
> problem. I've written a small program which uses libmylib.so and try to link
> it as follows:

>         g++ -o testprogram.exe testprogram.o -L/usr/src/DynLib -lmylib

> This results in the error:

        
> /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/../../../../i686-pc-cygwin/bin/ld:
> cannot find -lmylib

> For information the entire output when executing make clean:

> rm -f   PrintTest.o  PrintTest.exe.exe PrintTest.d *~
> make
> make[1]: Entering directory `/usr/src/dynlibtest'
> g++ -M  -Wall  PrintTest.cpp > PrintTest.d
> g++ -M  -Wall  PrintTest.cpp | sed s/\\.o/.d/ >> PrintTest.d
> make[1]: Leaving directory `/usr/src/dynlibtest'
> make[1]: Entering directory `/usr/src/dynlibtest'
> g++ -Wall    -c -o PrintTest.o PrintTest.cpp
> g++  -o PrintTest.exe   PrintTest.o  -L/usr/src/DynLib -lmylib
> /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/../../../../i686-pc-cygwin/bin/ld:
> cannot find -lmylib
> collect2: ld returned 1 exit status
> make[1]: *** [PrintTest.exe] Error 1
> make[1]: Leaving directory `/usr/src/dynlibtest'
> make: *** [clean] Error 2

> When using:

>         g++ -o PrintTest.exe PrintTest.o libmylib.so

> I get the error:

>         collect2: ld terminated with signal 11 [Segmentation fault]

> Can someone tell me what I'm doing wrong?

You cannot act with windows like with linux.  On windows shared libs
are dynamic link libraries (mylib.dll), and you cannot use symlinks to
point to a dll.  Say mylib-0.1.dll is you lib and mylib.dll is the
symlink then it is not possible to link against the symlink, windows
doesn't accept this as a library.  Anyway, we don't use the .dll's to
link against, but a special library called import library.
Looks like this (Cygwin default name) libmylib.dll.a, so we can have
also libmylib.a as the static lib.
Now if you link against this lib you write: gcc -o prog -I/lib -lmylib
The linker looks at first for libmylib.dll.a, then if there is no
importlib it looks for a static lib.
I always try to build a static lib at first.
If it succeeds it is just one step to get a dynamic link library from
these objects:
gcc -shared -o cyg${module}.dll -Wl,--out-implib=lib${module}.dll.a \
                  -Wl,--export-all-symbols \
                  -Wl,--enable-auto-import \
                  -Wl,--whole-archive $old_lib \
                  -Wl,--no-whole-archive ${dependency_libs}

The last (-Wl,--no-whole-archive) is important, even if you have no
dependency_libs.  Don't miss it!
${module} is 'mylib' to stay with your example and $old_lib is libmylib.a,
the static lib.  As an alternativ you can list all the objects here instead
of a static lib which is in fact just a bundle of object files.


HTH,

Gerrit
-- 
=^..^=
Maybe Charles will find some time to finish his docu about creating dll's;)


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019