autoconf fails linking in C++

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
paulotex
Posts: 19
Joined: Sun Jan 20, 2008 9:28 pm

autoconf fails linking in C++

Post by paulotex »

This is silly, but I don't know where to look further to solve it:

I'm trying to compile an autotools project in C++ (djvulibre) and lots of tests are failing because linking fails. For example, looking for -lm:

Code: Select all

$ CXXFLAGS="-I`psp-config -p`/include -I`psp-config -P`/include -G0 -fno-rtti" LDFLAGS="-L`psp-config -P`/lib -L`psp-config -p`/lib -lc -lpspuser" ./configure --host=psp --prefix=`psp-config -P` --disable-shared --enable-static --without-x --without-qt
...
checking for sqrt in -lm... no
...
In config.log:

Code: Select all

configure:22109: checking for sqrt in -lm
configure:22144: psp-g++ -o conftest  -I/Users/paulo/pspdev/psp/sdk/include -I/Users/paulo/pspdev/psp/include -G0 -fno-rtti  -L/Users/paulo/pspdev/psp/lib -L/Users/paulo/pspdev/psp/sdk/lib -lc -lpspuser conftest.cpp -lm   -lc -lpspuser >&5
/Users/paulo/pspdev/psp/lib/libc.a(_write.o): In function `_write':
libcglue.c:(.text+0x84): undefined reference to `sceIoWrite'
...
The code that fails (conftest.cpp) is:

Code: Select all

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char sqrt ();
int
main ()
{
return sqrt ();
  ;
  return 0;
}

But this code compiles fine in C:

Code: Select all

$ cp conftest.cpp conftest.c
$ psp-gcc -o conftest  -I/Users/paulo/pspdev/psp/sdk/include -I/Users/paulo/pspdev/psp/include -G0 -fno-rtti  -L/Users/paulo/pspdev/psp/lib -L/Users/paulo/pspdev/psp/sdk/lib -lc -lpspuser conftest.c -lm   -lc -lpspuser
cc1: warning: command line option "-fno-rtti" is valid for C++/ObjC++ but not for C
conftest.c:4: warning: conflicting types for built-in function ‘sqrt’
All tests that use the 'extern "C" ' are failing the same way.

I'm probably doing something wrong here, but I don't know what... I've tried changing the linking order of the libs, adding more libs, all to no avail. Any suggestions?

Thanks.
sedrik
Posts: 8
Joined: Thu Sep 04, 2008 5:06 pm

Post by sedrik »

add

Code: Select all

LIBS=-lstdc++
to your Makefile
paulotex
Posts: 19
Joined: Sun Jan 20, 2008 9:28 pm

Post by paulotex »

sedrik wrote:add

Code: Select all

LIBS=-lstdc++
to your Makefile
That was the solution, thanks! I did try it before, but not in the correct order. It should go before -lc, and I didn't try it. I knew it had to be something silly. Thanks again!
Post Reply