Re: Shared librares dependency at compile time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 27, 2012 at 12:10 PM, LiLy <xmlymt@xxxxxxxxxxx> 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@xxxxxxxxxxx and
gcc-help@xxxxxxxxxxx.  This message should only have gone to
gcc-help@xxxxxxxxxxx.  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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux