CentOS x86_64上编译32位demo程序
2014-07-16 13:00
423 查看
先写个hello world的简单程序
gcc -m32 a.c
先确保a.c能够编译链接成功,再去编译你的32位程序。
[root@localhost ~]# gcc -m32 hello.c
In file included from /usr/include/features.h:399:0,
from /usr/include/stdio.h:27,
from hello.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
# include <gnu/stubs-32.h>
^
compilation terminated.
[root@localhost ~]#
编译失败,缺少32位头文件。
使用yum安装i686的库
[root@localhost centos-release]# yum list glibc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
glibc.i686 2.17-55.el7 @base
glibc.x86_64 2.17-55.el7 @anaconda
[root@localhost centos-release]# yum install glibc.i686
yum安装时有个小插曲,提示GPG keys配置有问题:
The GPG keys listed for the "CentOS-7 - Base - 163.com" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
解决方法:
手动从163网站导入CentOS-7的key,我的版本是CentOS 7。
rpm -import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
安装glibc开发库:
[root@localhost ~]# yum list *glibc*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
compat-glibc.x86_64 1:2.12-4.el7.centos @anaconda
compat-glibc-headers.x86_64 1:2.12-4.el7.centos @anaconda
glibc.i686 2.17-55.el7 @base
glibc.x86_64 2.17-55.el7 @anaconda
glibc-common.x86_64 2.17-55.el7 @anaconda
glibc-devel.x86_64 2.17-55.el7 @anaconda
glibc-headers.x86_64 2.17-55.el7 @anaconda
Available Packages
glibc-devel.i686 2.17-55.el7 base
glibc-static.i686 2.17-55.el7 base
glibc-static.x86_64 2.17-55.el7 base
glibc-utils.x86_64 2.17-55.el7 base
[root@localhost ~]# yum install glibc-devel.i686
再次编译,发现编译成功,但是链接失败。
[root@localhost ~]# gcc -m32 hello.c
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
[root@localhost ~]#
缺少动态库libgcc
[root@localhost ~]# yum list libgcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
libgcc.x86_64 4.8.2-16.el7 @anaconda
Available Packages
libgcc.i686 4.8.2-16.el7 base
[root@localhost ~]# yum install libgcc.i686
libgcc安装成功后,再次编译
[root@localhost ~]# gcc -m32 hello.c
[root@localhost ~]# ./a.out
hello world
发现编程链接全部成功,OK,大功告成。
gcc -m32 a.c
先确保a.c能够编译链接成功,再去编译你的32位程序。
[root@localhost ~]# gcc -m32 hello.c
In file included from /usr/include/features.h:399:0,
from /usr/include/stdio.h:27,
from hello.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
# include <gnu/stubs-32.h>
^
compilation terminated.
[root@localhost ~]#
编译失败,缺少32位头文件。
使用yum安装i686的库
[root@localhost centos-release]# yum list glibc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
glibc.i686 2.17-55.el7 @base
glibc.x86_64 2.17-55.el7 @anaconda
[root@localhost centos-release]# yum install glibc.i686
yum安装时有个小插曲,提示GPG keys配置有问题:
The GPG keys listed for the "CentOS-7 - Base - 163.com" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
解决方法:
手动从163网站导入CentOS-7的key,我的版本是CentOS 7。
rpm -import http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
安装glibc开发库:
[root@localhost ~]# yum list *glibc*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
compat-glibc.x86_64 1:2.12-4.el7.centos @anaconda
compat-glibc-headers.x86_64 1:2.12-4.el7.centos @anaconda
glibc.i686 2.17-55.el7 @base
glibc.x86_64 2.17-55.el7 @anaconda
glibc-common.x86_64 2.17-55.el7 @anaconda
glibc-devel.x86_64 2.17-55.el7 @anaconda
glibc-headers.x86_64 2.17-55.el7 @anaconda
Available Packages
glibc-devel.i686 2.17-55.el7 base
glibc-static.i686 2.17-55.el7 base
glibc-static.x86_64 2.17-55.el7 base
glibc-utils.x86_64 2.17-55.el7 base
[root@localhost ~]# yum install glibc-devel.i686
再次编译,发现编译成功,但是链接失败。
[root@localhost ~]# gcc -m32 hello.c
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
[root@localhost ~]#
缺少动态库libgcc
[root@localhost ~]# yum list libgcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
libgcc.x86_64 4.8.2-16.el7 @anaconda
Available Packages
libgcc.i686 4.8.2-16.el7 base
[root@localhost ~]# yum install libgcc.i686
libgcc安装成功后,再次编译
[root@localhost ~]# gcc -m32 hello.c
[root@localhost ~]# ./a.out
hello world
发现编程链接全部成功,OK,大功告成。
相关文章推荐
- centos5.8 x86_64 gcc升级到4.4.7解决了编译32位程序的问题
- X86_64机器编译运行32位程序
- X86_64机器编译32位程序
- 在64位服务器上安装oracle 32位客户端只能被编译为x86的程序连接
- CentOS-6.4-x86_64-minimal Nginx编译和安装
- X86-64 CPU架构以及64 位GCC对程序编译处理的一些变化
- Ubuntu 64编译32位程序
- CentOS 7 x86_64 编译安装zabbix-2.4.2出错 MySQL library not found
- 在64位服务器上安装oracle 32位客户端只能被编译为x86的程序连接
- Centos&nbsp;5.7&nbsp;x86_64环境下编译CDH&nbsp;…
- centos6.6 x86_64下安装32位兼容包&openssl 32位
- centos 7 已经支持 gcc 编译32位程序
- ubuntu 64上的GCC如何编译32位程序
- Centos6.5_x86_64 编译安装Subversion-1.8.5
- (7) linux 编译并安装mysql-5.6.15.tar.gz ---> CentOS-6.6-x86_64 + mysql-5.6.15.tar.gz
- CentOS 5.4 x86_64 编译安装 MySQL 完全笔记
- x86_64平台编译链接汇编程序
- CentOS 6.5 x86_64 Hadoop 2.2.0 eclipse plugs编译
- CentOS-6.5-x86_64 最小化安装后,如何安装 man 程序?
- 在64位服务器上安装oracle 32位客户端只能被编译为x86的程序连接