views:

814

answers:

2

I'm trying to use someone else's Makefile to complile a very simple c++ library. The makefile is as follows:

JNIFLAGS=-O2 -pthread -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux

all:
    rm -f ../dist/libUtils.so
    g++ $(JNIFLAGS) -c -m32 -o com_markets_utils_dates_NativeTime.o com_markets_utils_dates_NativeTime.cpp
    g++ $(JNIFLAGS) -c -m32 -o DateUtil.o DateUtil.cpp
    g++ -pthread -m32 -shared -fPIC -o ../dist/libUtils.so DateUtil.cpp
    g++ -pthread -m32 -shared -fPIC -o ../dist/libNativeTime.so DateUtil.o com_markets_utils_dates_NativeTime.o

This compiles fine, but the linker complains:

...
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [all] Error 1

FYI, I am on Ubuntu 9.10 64bit.

+2  A: 

It seems you're compiling a 32 bit library on a 64 bit machine, however a 32 bit version of libstdc++ is not present.

Try apt-get install ia32-libs libc6-i386 libc6-dev-i386 lib32gcc1 lib32stdc++6

(btw. you're producing a .so , you should specify -fPIC when compiling your .cpp files as well)

nos
I had thought of that, however they are all installed - btw thanks for the -fPIC reminder, I should have caught that...
jwoolard
+2  A: 

Answering my own question:

Ths solution seems to be a bit of a hack, you need to create a symlink for the 32 bit version of the library (after installing the packages mentioned in @nos's answer):

$ sudo ln -s /usr/lib32/libstdc++.so.6 /usr/lib32/libstdc++.so

Once you've done this, the linker will automagically find the correct library to use.

jwoolard
Probably related to this bug https://bugs.launchpad.net/ubuntu/jaunty/+source/ia32-libs/+bug/360870/+viewstatus
nos