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

Re: CPP test program fails for x64 platform



On 31.03.2011 18:50, Matthias Klose wrote:
>> My questions to the community are:
>> - Why extern "C" causes GCC not to find "log" and "pow" from libm,
>> needed by libnetpbm?
>> - Why exactly the same configure script works OK for x32 platform?
>> - How to overcome the problem?
> 
> caused by the ld --no-add-needed default? Link libnetpbm.so with -lm.
> See http://wiki.debian.org/ToolChain/DSOLinking

Matthias, thank you a lot. "-Wl,--as-needed" argument looks to play the
essential role! So the original test script is now compiled without errors:

# g++ -o conftest conftest_orig.cpp -lnetpbm -lm

Correct me if I am wrong with points below:

* With "-Wl,--as-needed" the linker will invalidate all libraries, from
which no symbols are used by current module. "-lm" was ignored and that
caused the mentioned error message:

/usr/lib64/libnetpbm.so: undefined reference to `log'
/usr/lib64/libnetpbm.so: undefined reference to `pow'

* It also means that libnetpbm.so was incorrectly linked as it should
depend on libm. However it does not:

# ldd /usr/lib64/libnetpbm.so
    linux-vdso.so.1 =>  (0x00007fffe4777000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fa0a43dd000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fa0a4997000)

* If libnetpbm.so is correctly linked, "-Wl,--as-needed" will not break
the test anymore.

* The wiki page says: "Introducing --as-needed will show some sloppy
configure scripts, which fail to build with --as-needed" and that is
exactly this case, right?

Thank you.

-- 
With best regards,
Dmitry


Reply to: