C++ GCC -m32 标志:/usr/bin/ld:跳过不兼容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4052542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GCC -m32 flag: /usr/bin/ld: skipping incompatible
提问by Vahagn
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?
在 64 位主机上,我正在尝试使用-m32
选项构建共享库。这些库是否可以与常规 64 位库链接?
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
?
所以我的问题是:如何64_bit_library.so
并且32_bit_library.so
应该在 64 位主机上编译,32_bit_library.so
以便可以链接到64_bit_library.so
?
回答by Flexo
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.
无法将 32 位应用程序链接到 64 位库,反之亦然。问题是指针和类型一般不能在它们之间传递。通常,解决方法是生成其他大小的子进程并使用 IPC 与该进程通信。
Think about it this way: If I have a C trivial function:
这样想:如果我有一个 C 琐碎函数:
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?
如果它在 64 位库中并且我尝试从 32 位库中调用它,那么指针的另一半来自哪里?
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?
相反,如果它在 32 位库中并且我从 64 位应用程序中调用它,那么指针的另一半会发生什么?