如何在x64系统上将C代码编译为32位。

huangapple go评论87阅读模式
英文:

How to compile a c code as 32 bit on x64 system

问题

我正在尝试在一台x64机器上将C代码编译为32位,使用命令gcc -m32。但我遇到了以下错误:

pegasus@pegasus:~/Documents/CSE21_workshop$ gcc -m32 got_plt.c
/usr/bin/ld: 在搜索 -lgcc 时跳过不兼容的 /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a
/usr/bin/ld: 找不到 -lgcc: 没有那个文件或目录
/usr/bin/ld: 在搜索 -lgcc 时跳过不兼容的 /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a
/usr/bin/ld: 找不到 -lgcc: 没有那个文件或目录
collect2: 错误:ld 返回 1 退出状态

我已经安装了g++-multilibgcc-multilib
我的当前gcc版本:

pegasus@pegasus:~$ gcc --version
gcc (Ubuntu 8.4.0-3ubuntu2) 8.4.0
Copyright (C) 2018 Free Software Foundation, Inc.
这是自由软件; 请查看源代码以获取复制条件。没有
保证; 甚至适用于特定用途的适用性也没有。
英文:

I'm trying to compile a c code as 32 bit on a x64 machine.
using gcc -m32. But I'm getting the following errors

pegasus@pegasus:~/Documents/CSE21_workshop$ gcc -m32 got_plt.c 
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc: No such file or directory
collect2: error: ld returned 1 exit status

I had already installed g++-multilib and gcc-multilib.
My current gcc version:

pegasus@pegasus:~$ gcc --version
gcc (Ubuntu 8.4.0-3ubuntu2) 8.4.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

答案1

得分: 0

已解决。正如我提到的,我安装了多个gcc版本,这导致了错误。我删除了除gcc 11.3.0之外的所有gcc版本。现在一切正常。

英文:

Solved it. Like I mentioned I had multiple gcc installed. And it was causing error. I removed all gcc versions except one. gcc 11.3.0
It's working fine.

huangapple
  • 本文由 发表于 2023年5月28日 03:23:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定