delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/08/31/12:48:43

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
Message-ID: <4C7D3250.8080902@gmail.com>
Date: Tue, 31 Aug 2010 12:48:16 -0400
From: Tomas Staig <tomas DOT staig AT gmail DOT com>
User-Agent: Thunderbird 2.0.0.24 (X11/20100317)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Linking shared libraries problem
References: <4C7AE88B DOT 2000309 AT gmail DOT com> <4C7B0ECF DOT 8050209 AT cygwin DOT com>
In-Reply-To: <4C7B0ECF.8050209@cygwin.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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

Larry Hall (Cygwin) wrote:
> On 8/29/2010 7:08 PM, Tomás Staig wrote:
>> Hi,
>> I have been trying to port some software from Linux (Scientific 
>> Linux/RedHat)
>> to windows using Cygwin. I have been able to port most of it with little
>> changes but I encountered a problem when linking shared libraries. It 
>> seems
>> that the chain of dependencies is not included when linking. 
>> Furthermore, ldd
>> does not show the dependency libraries as in Linux. I have tried both 
>> using
>> the import libraries (%.dll.a) and linking the dll files (%.dll) 
>> directly.
>>
>> I have arranged a small example program that reproduces this effect.
>> Used Ubuntu 8.04 to and "CYGWIN_NT-5.1" version "1.7.6(0.230/5/3) 
>> 2010-08-16
>> 16:06" on top of a 32-bits Windows XP Machine to test the above 
>> examples.
>
> <snip>
>
>> As you can see, there is no reference to liby.dll. I could add the 
>> library
>> (-ly) directly to the compiling line of main and it works, but the 
>> truth is
>> that it would not be a good approach, since in the software I'm 
>> trying to
>> port, there are several dependent modules, so the last ones would 
>> have an
>> incredibly large list of dependencies.
>>
>> So, am I doing something wrong? Is there any way to add the 
>> dependency to be
>> shown with ldd or any workaround(maybe a linker flag or something) to 
>> make
>> the above example work?
>
> The Windows loader requires full resolution at link time.  You need to 
> list
> at least the import libraries for all dependencies if you want the link
> to succeed.  Sorry, that's just the way Windows works.
>
Thanks for your reply. I have found a workaround, however.
Probably not the best thing to do in general, but for my case it is 
pretty useful:

Makefile in Cygwin:
all:
g++ -c x.cpp
g++ -c y.cpp
g++ -shared -Wl,--output-def,liby.def -Wl,-out-implib=liby.dll.a 
-Wl,-export-all-symbols -Wl,-enable-auto-import -Wl,-whole-archive  y.o 
-Wl,-no-whole-archive -o liby.dll
g++ -shared -Wl,-out-implib=libx.dll.a -Wl,-export-all-symbols 
-Wl,-enable-auto-import -Wl,-whole-archive x.o liby.def 
-Wl,-no-whole-archive -L./ -ly -o libx.dll
g++ -o main main.cpp -L./ -lx

If anyone is going to use this, be aware that it might get you "multiple 
definition" problems. I still haven't checked how this behaves in the 
project I'm porting, but in this tiny example it works flawlessly.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


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