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

Re: Bullseye: Linker Can't Find libgps Library



On 2020-07-12 15:44 -0600, Charles Curley wrote:

> On Sun, 12 Jul 2020 22:04:54 +0200
> Sven Joachim <svenjoac@gmx.de> wrote:
>
>> I am rather surprised that it does, for I have learned that you always
>> need to put libraries to link with at the end of the gcc commandline,
>> i.e.
>>
>> gcc -Wall -ggdb -o gpsclient gpsclient.c -lm -lgps
>>
>> should work.
>
> Bingo.
>
> charles@white:~/versioned/gpsclient$ gcc -Wall -o gpsclient gpsclient.c -lm -lgps
> gpsclient.c:72:2: warning: #warning Setting up for API version 9.0 [-Wcpp]
>    72 | #warning Setting up for API version 9.0
>       |  ^~~~~~~
> charles@white:~/versioned/gpsclient$
>
> Worked correctly. Thank you. Interesting.
>
> This is a change from Buster, gcc (Debian 9.3.0-14) 9.3.0 versus gcc
> (Debian 8.3.0-6) 8.3.0. I conjecture the reason is so that gcc can
> accommodate multiple source files on one line, each with their own
> libraries. Something like:
>
> gcc -Wall -o snark foo.c -la -lb -lc bar.c -lb -lc -ld

Not really, the reason is that in Bullseye gcc now passes the
--as-needed option to the linker to reduce unnecessary linking of
libraries (and dependencies in the Debian package system).  According to
the binutils documentation,

,----
| '--as-needed' causes a DT_NEEDED tag to only be emitted for a library
| that _at that point in the link_ satisfies a non-weak undefined symbol
| reference from a regular object file or, if the library is not found in
| the DT_NEEDED lists of other needed libraries, a non-weak undefined
| symbol reference from another needed dynamic library.  Object files or
| libraries appearing on the command line _after_ the library in question
| do not affect whether the library is seen as needed.
`----

HTH,
    Sven


Reply to: