www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/22/11:16:59

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: 2 and more libraries in one project
Date: Mon, 22 Dec 1997 16:48:02 +0100
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 53
Message-ID: <349E8BB2.3828BDBB@LSTM.Ruhr-UNI-Bochum.De>
References: <Pine DOT LNX DOT 3 DOT 91 DOT 971222165522 DOT 737B-100000 AT cas3 DOT zlin DOT vutbr DOT cz>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Petr Mrazek wrote:
> 
> Hi,
> I had this problem:
> 
> Module foo.c contains only int main(void).
> Module libfoo1.c contains function for example void foo1(void)
> Module libfoo2.c function void foo2(void)
> 
> I create libraries libfoo1.a and libfoo2.a then add them to project
> foo with module foo.c.
> 
> 1. All works fine when main calls foo1 and/or foo2 and this foos don't
> call another foo (from other library) like this:
> main -> foo1
>      \-> foo2
> 
> 2. But when I want to call foo1 from main and foo2 from foo1 linker says
> "unresolved external foo2" or something like this.
> ( main -> foo1 -> foo2 )
> 
> All works fine when both foo1 and foo2 are in one library.
> 
> Is it bug of linker?
Hmm. It's a feature. The thing is that ld makes only one
pass through libaries to resolve external symbols. So in
your second  example the cure is to say
gcc -/Other Options/ -lfoo1 -lfoo2
hence, libfoo1.a is read first, the external symbol foo1  that
showed up in the main module resolved and another unknown symbol,
foo2, put onto the to-do list. Then it looks through libfoo2.a and
finds foo2, resolves the reference, et voila. 

Ugly is, when you have modules calling each other across libraries, 
then you need to say something like -lfoo1 -lfoo2 -lfoo1 and have to
read
foo1 twice.


-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


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