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

流过昼夜 提交于 2019-11-30 03:00:29

问题


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:


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?



来源:https://stackoverflow.com/questions/4052542/gcc-m32-flag-usr-bin-ld-skipping-incompatible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!