test.c
#include <stdio.h> int main() { printf("sizeof long is %d\n",sizeof(long)); return 0; }
64位编译
[[email protected] desktop]$ gcc test.c[[email protected] desktop]$ file a.outa.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped[[email protected] desktop]$
32位编译
[[email protected] desktop]$ gcc -m32 test.c
错误1:缺少32位头文件
解决方法:
[[email protected] desktop]$ yum install glibc.i686
错误2:再次编译,发现编译成功,链接失败,提示如下错误
解决方法:
先查看64位文件版本
[[email protected] desktop]$ yum list libgcc 已加载插件:fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 已安装的软件包 libgcc.x86_64 4.8.2-8.el6 @hop5
由于yum提供的32版本低于64位的版本,使用yum install libgcc.i686会安装失败,因此需自己下载32位版本进行安装
下载地址:https://pkgs.org/download/libgcc
安装libgcc.i686
[[email protected] desktop]$ sudo rpm -ivh libgcc-4.8.5-28.el7.i686.rpm
安装完成后重新编译程序
[[email protected] desktop]$ gcc -m32 test.c [[email protected] desktop]$ file a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped [[email protected] desktop]$ a.out sizeof long is 4 [[email protected] desktop]$
显示已经可以编译32位程序了。
原文地址:https://www.cnblogs.com/mxly/p/9583580.html
时间: 2024-10-10 04:21:39