Ohad Horesh
Ohad Horesh

Reputation: 4390

Linking with x86 shared library on Linux x64

I'm trying to link with x86 shared library on x64 Ubuntu 11.04 Natty Narwhal but I get the following message:

/usr/bin/ld: skipping incompatible ./bin/libshared.so when searching for -lshared
/usr/bin/ld: cannot find -lshared

Some details:
The shared library name is libshared.so
The shared library is build on x86 OS.
I have installed lib32stdc++6.
The makefile looks like this:

test: main.o
    g++ -mi386linux -L./bin -lshared main.o -o test

main.o: main.cpp
    g++ -m32 -c main.cpp -o main.o

Any ideas?

Edit: After changing -mi386linux flag to -m32 I got this error:

/usr/bin/ld: cannot find -lshared  
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

running locate I found libstdc++.so in the following places:

/usr/lib/x86_64-linux-gnu/libstdc++.so.6  
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.14  
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5/libstdc++.so  
/usr/lib32/libstdc++.so.6  
/usr/lib32/libstdc++.so.6.0.14

Upvotes: 5

Views: 8066

Answers (2)

paulsm4
paulsm4

Reputation: 121599

Definitely use "-m32", and definitely put "-L/usr/lib32" as early as possible in your build command.

Upvotes: 0

TomH
TomH

Reputation: 9220

I'm not sure what the -mi386linux is supposed to be about, but if you replace it by -m32 on the link line then I suspect this will work.

Upvotes: 3

Related Questions