解决《自制编译器》64位CentOS下cbc编译执行成功

前端之家收集整理的这篇文章主要介绍了解决《自制编译器》64位CentOS下cbc编译执行成功前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

搞了两晚上,终于hello了\(^o^)/,先上图

简单说:

1、编译、汇编源文件

将/usr/bin/as重命名

mv /usr/bin/as/usr/bin/as_bk

新建/usr/bin/as,并输入下面这样的内容

vi /usr/bin/as

*******************************

#!/bin/sh



/usr/bin/as_bk --32 $*

*******************************

赋予执行权限

chmod 755 /usr/bin/as

然后编译cbc/test里的hello.cb

​cbc /usr/local/cbc-1.0/test/hello.cb

之后报错信息不管,只要能在/usr/lib下看到

hello.shello.o就ok

2、安装32位函数库(我的64位centos里面没有32位库)

参照http://blog.csdn.net/liushihuidfg/article/details/46442209

搜索可用的glibc软件包

[root@localhost ~]# yum search glibc
已加载插件:fastestmirror,langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.sina.cn
 * updates: mirrors.cqu.edu.cn
================================= N/S matched: glibc =================================
glibc-common.x86_64 : Common binaries and locale data for glibc
compat-glibc.x86_64 : Compatibility C library
compat-glibc-headers.x86_64 : Header files for development using standard C libraries.
glibc.i686 : The GNU libc libraries
glibc.x86_64 : The GNU libc libraries
glibc-devel.i686 : Object files for development using standard C libraries.
glibc-devel.x86_64 : Object files for development using standard C libraries.
glibc-headers.x86_64 : Header files for development using standard C libraries.
glibc-static.i686 : C library static libraries for -static linking.
glibc-static.x86_64 : C library static libraries for -static linking.
glibc-utils.x86_64 : Development utilities from GNU C library
kdesdk-kmtrace.x86_64 : Assist with malloc debugging using glibc's "mtrace"
                      : functionality
kernel-headers.x86_64 : Header files for the Linux kernel for use by glibc
latrace.i686 : LD_AUDIT feature frontend for glibc 2.4+
latrace.x86_64 : LD_AUDIT feature frontend for glibc 2.4+

  名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]# yum install glibc.i686

安装32位的glibc.i686

3、建立软连接

ln -sv/usr/lib/libc.so.6 libc.so

因为每次ld的时候系统默认去找libc.so,这个配置到哪里的不知道,简单点就直接软连接

4、最后一步:链接执行

还是嘴儿http://blog.csdn.net/liushihuidfg/article/details/46442209

ld -melf_i386 --dynamic-link /usr/lib/ld-linux.so.2 -lc -L /usr/lib -ohello hello.o

后执行

​​./hello

完结撒花\(^o^)/

原文链接:https://www.f2er.com/centos/378422.html

猜你在找的CentOS相关文章