views:

53

answers:

1

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?

+1  A: 

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?

awoodland
If you were really careful you might be able to play some games with typedef, mmap with the MAP_32BIT flag and shared memory segments but it's an awful lot of hassle!
awoodland