Shared librares dependency at compile time

Fri Jul 27 19:56:00 GMT 2012

Hi Ian,

Thanks for your quick reply!

Sorry, It's the first time for me to post to gcc mailing list. I have removed now.

Glad to get your confirmations. Further more, could you please give me some links that introduce ld internals?

BTW, I guess gold means google ld. Regarding 1.1), I suppose gold will also work in similar way, since the obj/lib file formats are same.

Best Regards,

> Date: Fri, 27 Jul 2012 12:19:26 -0700
> Subject: Re: Shared librares dependency at compile time
> From:
> To:
> CC:;
> On Fri, Jul 27, 2012 at 12:10 PM, LiLy <> wrote:
>> I have two existing shared libraries,
>> depends on is dynamically linked with
>> ). Now I want to compile an application which uses both and
> Please never send e-mail to both and
> This message should only have gone to
> Please take any followups to gcc-help only.
> Thanks.
>> 1. On Linux, following command can pass
>> gcc -Wall -o app app.c -L.. -la
>> Note: -lb is not specified in the command
>> I have several questions:
>> 1). How is also linked actually while dynamic linking
> There are two answers, one using GNU ld, one using gold.
>> It seems the linker knows according to the NEEDED entry in
>> dynamic section of contains the name of
> That is how GNU ld works, yes.
>> Dynamic
>> symbol table is also used to resolved symbols during linkage stage of
>> compile, right?(since the program still can compile if the shared
>> libraries are stripped)
> Correct.
>> 2) With -la or without -la
>> We have two choices:
>> i) gcc -Wall -o app app.c -L.. -la
>> ii) gcc -Wall -o app app.c -L.. -la -lb
>> Which one is more preferred?
> If your application refers to symbols in libb, then the second one is
> preferred. If your application only uses symbols in liba, then the
> first one is preferred. In general you should link your application
> against the libraries that your application refers to directly.
>> 2. On Cygwin, while, the same command can not pass
>> gcc -Wall -o app app.c -L.. -la
>> (same as on Linux, no -lb )
>> The error report reads like this: undefined reference to xxx(symbols defined in
>> Questions:
>> What's the difference between gcc's behaviors on Linux and Cygwin?
> The shared library implementations on GNU/Linux and cygwin are
> completely different.
> Ian

More information about the Gcc-help mailing list