简体   繁体   English

在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

It gives me an error: 它给我一个错误:

ld: i386 architecture of input file `ConditionalBranching.o' is incompatible with i386:x86-64 output

I tried using flag -m32 or --32, but ld dont take them. 我尝试使用标志-m32或--32,但ld不要使用它们。 I cannot find a solution by reading the man page of ld. 我无法通过阅读ld的手册页找到解决方案。 How can I generate a 32-bit binary from my 32-bit shared object? 如何从32位共享库生成32位二进制文​​件?

Your linker is attempting to create a 64-bit binary, but your assembly code was assembled for a 32-bit architecture. 您的链接器正在尝试创建64位二进制文​​件,但是您的汇编代码已针对32位体系结构进行了汇编。 This creates a mismatch. 这会造成不匹配。

Fix this by passing the -m elf_i386 flag to your linker, explicitly instructing it to create a 32-bit binary. 通过将-m elf_i386标志传递给链接器,明确指示其创建32位二进制文​​件,可以解决此问题。

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

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