This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Broken SO due to dropped dependencies
- From: Chung-Ju Wu <jasonwucj at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Miguel Guedes <miguel dot a dot guedes at gmail dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Sat, 30 Mar 2013 01:29:20 +0800
- Subject: Re: Broken SO due to dropped dependencies
- References: <kj44bb$plm$1 at ger dot gmane dot org> <CAKOQZ8wYCipwEUD5OW_7fhvx1QsXwAeUG6283HbpH2NxKfugsg at mail dot gmail dot com> <kj4a3q$f26$1 at ger dot gmane dot org> <CAKOQZ8zyH4gY0aD39=NieOLgTnpqdmt5z1aVPMX1vauw6VFKvw at mail dot gmail dot com>
2013/3/29 Ian Lance Taylor <iant@google.com>:
> On Fri, Mar 29, 2013 at 7:56 AM, Miguel Guedes
> <miguel.a.guedes@gmail.com> wrote:
>> I take it you don't think there's anything wrong with GCC? Is the
>> different behaviour between GCC and clang expected in this case?
>
> OK, I looked a bit closer, and I see the problem. You are listing the
> -l options before the .o files. With GCC, that means that the -l
> options are effectively ignored. I guess clang must rearrange the -l
> options in that case, although I don't know how that could work
> reliably while preserving Unix linking semantics.
>
> Move your -l options after your .o files.
>
> Ian
To my understanding, the linking order is required for static libraries.
There is no order requirement for object files or dynamic libraries.
For example, given a file z.c:
[z.c]
#include <math.h>
int main(int argc, char **argv)
{
float f;
f = sqrt (argc);
return ((int) f);
}
<A>
$ gcc -c z.c
$ gcc -lm z.o
<B>
$ gcc -c z.c
$ gcc -static -lm z.o
Case <A> is ok.
But case <B> will show up "undefined reference to `sqrt'" message
unless you place '-lm' after z.o.
Another example, given two files f.c and f2.c:
[f.c]
extern int func (int);
int main()
{
int result;
result = func (9);
return result;
}
[f2.c]
int func(int k)
{
return k;
}
$ gcc -c f.c
$ gcc -c f2.c
$ ar rc libf2.a f2.o
<C>
$ gcc f.o libf2.a
<D>
$ gcc libf2.a f.o
<E>
$ gcc -L. -lf2 f.o
Case <C> is ok.
But case <D> and <E> both show up "undefined reference to `func'" message.
So my guess is that Miguel used some symbols which
reside in static libraries such as libomnis.a or other -lxxxxx.
Best regards,
jasonwucj