英文:
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++-multilib
和gcc-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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论