LSB AppChecker: GCC Links Against Unused Libraries

I check portability of a shared object (.so) using the LSB AppChecker.
One of the problems he reports is that there is one external library (libm.so.6) that is not used, but is connected in any way.

How can I prevent GCC from linking to this unnecessary library?

EDIT:
The result of the ldd command for my shared object is:

    linux-gate.so.1 =>  (0x009ff000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x003dc000)
    libm.so.6 => /lib/libm.so.6 (0x00110000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00137000)
    libc.so.6 => /lib/libc.so.6 (0x0021d000)
    /lib/ld-linux.so.2 (0x0097f000)
+3
source share
2 answers

-Wl, -as-needed . , .

$ g++ -o test test.cpp -lm; readelf -d test|grep '(NEEDED)'
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
$ g++ -o test test.cpp -lm -Wl,-as-needed; readelf -d test|grep '(NEEDED)'                                                                    
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
+4

-lm , , , , . , ++, , , libstd++, .

% ldd /usr/lib/libstdc++.so.6                                                                                      
        linux-gate.so.1 =>  (0x4001e000)
        libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x40127000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x4014d000)
        /lib/ld-linux.so.2 (0x40000000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x402b1000)
-1

Source: https://habr.com/ru/post/1707990/


All Articles