This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Shared librares dependency at compile time


Hi Ian,

Thanks for your quick reply!

Sorry, It's the first time for me to post to gcc mailing list. I have removed gcc@gcc.gnu.org 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,
Ly

----------------------------------------
> Date: Fri, 27 Jul 2012 12:19:26 -0700
> Subject: Re: Shared librares dependency at compile time
> From: iant@google.com
> To: xmlymt@hotmail.com
> CC: gcc@gcc.gnu.org; gcc-help@gcc.gnu.org
>
> On Fri, Jul 27, 2012 at 12:10 PM, LiLy <xmlymt@hotmail.com> wrote:
>>
>> I have two existing shared libraries liba.so, libb.so.
>> Liba.so depends on libb.so(liba.so is dynamically linked with libb.so
>> ). Now I want to compile an application which uses both liba.so and
>> libb.so.
>
>
> Please never send e-mail to both gcc@gcc.gnu.org and
> gcc-help@gcc.gnu.org. This message should only have gone to
> gcc-help@gcc.gnu.org. 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 libb.so also linked actually while dynamic linking liba.so?
>
> There are two answers, one using GNU ld, one using gold.
>
>> It seems the linker knows libb.so according to the NEEDED entry in
>> dynamic section of liba.so(which contains the name of libb.so)?
>
> 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 libb.so)
>>
>> 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
 		 	   		  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]