在64位平台上使用ld生成32位可执行文件 [英] Use ld on 64-bit platform to generate 32-bit executable
问题描述
我编写了一个程序集,该程序集与:
I wrote an assembly that is assemble with:
$as --32 -o hello.o hello.s
然后我尝试使用以下命令生成可执行文件:
Then I tried to generate an executable with:
$ld -o hello hello.o
它给我一个错误:
ld: i386 architecture of input file `ConditionalBranching.o' is incompatible with i386:x86-64 output
我尝试使用标志-m32或--32,但是ld不接受它们.我无法通过阅读ld的手册页找到解决方案.如何从32位共享库中生成32位二进制文件?
I tried using flag -m32 or --32, but ld dont take them. I cannot find a solution by reading the man page of ld. How can I generate a 32-bit binary from my 32-bit shared object?
推荐答案
您的链接器正在尝试创建64位二进制文件,但是您的汇编代码已针对32位体系结构进行了汇编.这会造成不匹配.
Your linker is attempting to create a 64-bit binary, but your assembly code was assembled for a 32-bit architecture. This creates a mismatch.
通过将-m elf_i386
标志传递给链接器,明确指示其创建32位二进制文件,可以解决此问题.
Fix this by passing the -m elf_i386
flag to your linker, explicitly instructing it to create a 32-bit binary.
这篇关于在64位平台上使用ld生成32位可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!