Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC -m32 flag: /usr/bin/ld: skipping incompatible

On 64 bit host I am trying to build shared libraries with -m32 option. Is it possible for these libraries to be linked with regular 64 bit libraries?

I am doing something like this:

g++ -m32 -shared source.cpp -l 64_bit_library.so -o 32_bit_library.so

and getting error messages like this:

/usr/bin/ld: skipping incompatible 64_bit_library.so

So my question is: how 64_bit_library.so and 32_bit_library.so should be compiled on 64 bit host, to make it possible for 32_bit_library.so to be linked against 64_bit_library.so?

like image 580
Vahagn Avatar asked Oct 29 '10 13:10

Vahagn


1 Answers

It's not possible to link 32 bit applications against 64 bit libraries and vice versa. The problem is that pointers and types in general can't be passed between them. Normally the workaround is to spawn a child process of the other size and use IPC to communicate with that process.

Think about it this way: If I have a C trivial function:

extern void foo(void*); 

If it's in a 64bit library and I try and call it from a 32bit library where does the other half of the pointer come from?

Conversely if it's in a 32bit library and I call it from a 64bit application what happens to the other half of the pointer which I would have to lose to call it?

like image 121
Flexo Avatar answered Oct 17 '22 21:10

Flexo