简体   繁体   English

如何编译与 32 位库链接的 64 位文件

[英]How to compile 64-bit file linking with 32-bit library

My system is Centos 5.8 64-bit, and I want to compile a file linking with 32-bit library.我的系统是Centos 5.8 64位,我想编译一个链接32位库的文件。 I add -m32 while compiling, but the result shows "i386:x86-64 architecture of input file `gc_basic_call_model_voice_video_3g_cnf_nbup.o' is incompatible with i386 output".我在编译时添加了 -m32,但结果显示“输入文件 `gc_basic_call_model_voice_video_3g_cnf_nbup.o' 的 i386:x86-64 架构与 i386 输出不兼容”。 It seems that the file can't be compiled on 32-bit.似乎无法在 32 位上编译该文件。 But if I don't add -m32, the library can't be compiled.但是如果我不加-m32,这个库就编译不出来了。 How to compile the file successfully, thanks!如何成功编译文件,谢谢!

You can't mix 32-bit and 64-bit code in the same program.不能在同一个程序中混合使用 32 位和 64 位代码。 The compiler is telling you that one of your .o files is compiled as a 64-bit object, so it can't be linked into a 32-bit executable.编译器告诉您,您的一个.o文件被编译为 64 位 object,因此无法链接到 32 位可执行文件。 You'll need to recompile that object file, and probably others as well, from source code using -m32 for everything.您需要使用-m32从源代码重新编译 object 文件,可能还有其他文件。

suppose you compiled a 32 bit version of your program (let's call it foo.c ) in the following manner:假设您按以下方式编译了程序的 32 位版本(我们称之为 foo.c ):

gcc -m32 -c foo.c -o foo.o

You should then call the linker on it using the -melf_i386 flag.然后,您应该使用 -melf_i386 标志在其上调用 linker。

ld <whatever commands / flags you gave earlier> -melf_i386

Example:例子:

ld -o foo.bin --oformat binary basic.o -melf_i386

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM