[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:29, Dmitry Katsubo wrote:
> Dear developers,
> 
> I hope somebody in this maillist can help me with my (perhaps trivial)
> problem.
> 
> I have written autoconf script, which among all other checks performs
> the following test:
> 
> AC_LANG([C++])
> ...
> AC_SEARCH_LIBS([pnm_readpnminit], [netpbm pnm])
> 
> The resulting configure script works fine for Debain x32 and Open SuSE
> x32, but when it came to x64 platform the following problem occurred for
> the above mentioned test, that generates the following program:
> 
> === conftest_orig.cpp ===
> #ifdef __cplusplus
> extern "C"
> #endif
> char pnm_readpnminit ();
> int
> main ()
> {
> return pnm_readpnminit ();
>   ;
>   return 0;
> }
> === end ===
> 
> # g++ -o conftest -g -Wl,--as-needed conftest_orig.cpp -lnetpbm -lm
> /usr/lib64/libnetpbm.so: undefined reference to `log'
> /usr/lib64/libnetpbm.so: undefined reference to `pow'
> collect2: ld returned 1 exit status
> 
> When I modified the test program by removing the "#ifdef", it starts to
> work (as expected by configure script):
> 
> === conftest.cpp ===
> char pnm_readpnminit ();
> int
> main ()
> {
> return pnm_readpnminit ();
>   ;
>   return 0;
> }
> === end ===
> 
> # g++ -o conftest -g -Wl,--as-needed conftest.cpp -lnetpbm -lm
> /root/tmp/cc2mdVNX.o: In function `main':
> /work/conftest.cpp:5: undefined reference to `pnm_readpnminit()'
> collect2: ld returned 1 exit status
> 
> 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


Reply to: