GNU 编译器家族 GCC 介绍
作 为自由软件的旗舰项目,Richard Stallman 在十多年前刚开始写作 GCC 的时候,还只是把它当作仅仅一个C 程序语言的编译器;GCC 的意思也只是 GNU C Compiler 而已。经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言;它现在还支持 Ada 语言,C++ 语言,Java 语言,Objective C 语言,Pascal 语言,COBOL 语言,以及支持函数式编程和逻辑编程的 Mercury 语言,等等。而 GCC 也不再单只是 GNU C 语言编译器的意思了,而是变成了 GNU Compiler Collection 也即是 GNU 编译器家族的意思了
另一方面,说到 GCC 对于各种硬件平台的支持,概括起来就是一句话:无所不在。几乎所有有点实际用途的硬件平台,甚至包括有些不那么有实际用途的硬件平台,比如 Don Knuth 设计的 MMIX 计算机,GCC 都提供了完善的支持。
如果把我们自己的程序语言的实现建立于 GCC 之上,也立刻使得我们的程序语言的实现版本可以运行在几乎所有有用的硬件平台之上。这对于程序语言的作者来说,也是一个确实的有极大诱惑力的好处。
环境:
操作系统是IBM Aix5.1
机器为IBM,7044-170
Processor Type: PowerPC_POWER3
Number Of Processors: 1
Processor Clock Speed: 333 MHz
CPU Type: 64-bit
Kernel Type: 32-bit
1. Installing the RedHat Package Manager (RPM)
在安装GCC软件之前,必须安装RPM - the RedHat Package Manager。
你需要用installp安装RPM包, 下载此包的地址为:
ftp://ftp.software.ibm.com/aix/freeSoftwa...LLP/ppc/rpm.rte
安装rpm 包,必须以root 用户操作,命令如下:
# installp -qacXgd rpm.rte rpm.rte
+-----------------------------------------------------------------------------+
Pre-installation Verification...
+-----------------------------------------------------------------------------+
Verifying selections...done
Verifying requisites...done
Results...
SUCCESSES
---------
Filesets listed in this section passed pre-installation verification
and will be installed.
Selected Filesets
-----------------
rpm.rte 3.0.5.36 # RPM Package Manager
<< End of Success Section >>
FILESET STATISTICS
------------------
1 Selected to be installed, of which:
1 Passed pre-installation verification
----
1 Total to be installed
+-----------------------------------------------------------------------------+
Installing Software...
+-----------------------------------------------------------------------------+
installp: APPLYING software for:
rpm.rte 3.0.5.36
. . . . . << Copyright notice for rpm.rte >> . . . . . . .
Licensed Materials - Property of IBM
5765E6100
© Copyright International Business Machines Corp. 2000, 2002.
© Copyright Regents of the University of California 1990, 1993, 1994, 1995.
© Copyright Jean-loup Gailly and Mark Adler, 1995 - 1998.
© Copyright The President and Fellows of Harvard University 1995, 1996.
© Copyright Julian R Seward, 1996 - 2000
© Copyright Sleepycat Software, 1990 - 2000
All rights reserved.
US Government Users Restricted Rights - Use, duplication or disclosure
restricted by GSA ADP Schedule Contract with IBM Corp.
. . . . . << End of copyright notice for rpm.rte >>. . . .
Please wait...
Finished processing all filesets. (Total time: 8 mins 19 secs).
+-----------------------------------------------------------------------------+
Summaries:
+-----------------------------------------------------------------------------+
Installation Summary
--------------------
Name Level Part Event Result
-------------------------------------------------------------------------------
rpm.rte 3.0.5.36 USR APPLY SUCCESS
rpm.rte 3.0.5.36 ROOT APPLY SUCCESS
#
2.Using the RedHat Package Manager (RPM)
使用RPM的完整信息详见www.rpm.org. 基本的安装操作参数:
-i: install
-e: erase
-q: query
--help: help
rpm程序在/opt/freeware/bin/中
#cd /opt/freeware/bin/
# ./rpm
RPM version 3.0.5
Copyright © 1998 - Red Hat Software
This may be freely redistributed under the terms of the GNU GPL
usage: rpm {--help}
rpm {--version}
rpm {--initdb} [--dbpath <dir>]
rpm {--install -i} [-v] [--hash -h] [--percent] [--force] [--test]
[--replacepkgs] [--replacefiles] [--root <dir>]
[--excludedocs] [--includedocs] [--noscripts]
[--rcfile <file>] [--ignorearch] [--dbpath <dir>]
[--prefix <dir>] [--ignoreos] [--nodeps] [--allfiles]
[--ftpproxy <host>] [--ftpport <port>] [--justdb]
[--httpproxy <host>] [--httpport <port>]
[--noorder] [--relocate oldpath=newpath]
[--badreloc] [--notriggers] [--excludepath <path>]
[--ignoresize] file1.rpm ... fileN.rpm
rpm {--upgrade -U} [-v] [--hash -h] [--percent] [--force] [--test]
[--oldpackage] [--root <dir>] [--noscripts]
[--excludedocs] [--includedocs] [--rcfile <file>]
[--ignorearch] [--dbpath <dir>] [--prefix <dir>]
[--ftpproxy <host>] [--ftpport <port>]
[--httpproxy <host>] [--httpport <port>]
[--ignoreos] [--nodeps] [--allfiles] [--justdb]
[--noorder] [--relocate oldpath=newpath]
[--badreloc] [--excludepath <path>] [--ignoresize]
file1.rpm ... fileN.rpm
rpm {--query -q} [-afpg] [-i] [-l] [-s] [-d] [-c] [-v] [-R]
[--scripts] [--root <dir>] [--rcfile <file>]
[--whatprovides] [--whatrequires] [--requires]
[--triggeredby] [--ftpport] [--ftpproxy <host>]
[--httpproxy <host>] [--httpport <port>]
[--ftpport <port>] [--provides] [--triggers] [--dump]
[--changelog] [--dbpath <dir>] [targets]
rpm {--verify -V -y} [-afpg] [--root <dir>] [--rcfile <file>]
[--dbpath <dir>] [--nodeps] [--nofiles] [--noscripts]
[--nomd5] [targets]
rpm {--setperms} [-afpg] [target]
rpm {--setugids} [-afpg] [target]
rpm {--freshen -F} file1.rpm ... fileN.rpm
rpm {--erase -e} [--root <dir>] [--noscripts] [--rcfile <file>]
[--dbpath <dir>] [--nodeps] [--allmatches]
[--justdb] [--notriggers] rpackage1 ... packageN
rpm {-b|t}[plciba] [-v] [--short-circuit] [--clean] [--rcfile <file>]
[--sign] [--nobuild] [--timecheck <s>] ]
[--target=platform1[,platform2...]]
[--rmsource] [--rmspec] specfile
rpm {--rmsource} [--rcfile <file>] [-v] specfile
rpm {--rebuild} [--rcfile <file>] [-v] source1.rpm ... sourceN.rpm
rpm {--recompile} [--rcfile <file>] [-v] source1.rpm ... sourceN.rpm
rpm {--resign} [--rcfile <file>] package1 package2 ... packageN
rpm {--addsign} [--rcfile <file>] package1 package2 ... packageN
rpm {--checksig -K} [--nopgp] [--nogpg] [--nomd5] [--rcfile <file>]
package1 ... packageN
rpm {--rebuilddb} [--rcfile <file>] [--dbpath <dir>]
rpm {--querytags}
#
3.下载GCC软件包
到http://www-1.ibm.com/servers/aix/products/aixos/linux/download.html上下载gcc
2.9.aix51.020209 (5.1)
注意:installing package gcc-2.9.aix51.020209-4 needs 27Mb on the /opt filesystem
以root用户执行如下步骤:
# /opt/freeware/bin/rpm -i gcc-2.9.aix51.020209-4.aix5.1.ppc.rpm
#
# find / -name "gcc" -print
/opt/freeware/GNUPro/bin/gcc
/usr/bin/gcc
/usr/local/bin/gcc
你可以在shell的提示符号下键入gcc -v,萤幕上就会显示出你目前正在使用的GCC的版本.在我的系统上,执行
gcc -v的结果是:
# gcc -v
Reading specs from /usr/bin/../lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/specs
gcc version 2.9-aix51-020209
4.测试方法
只要执行gcc时,附加 -v这个参数(switch),就能找出你所用的这版gcc,自动帮你定义了什麽符号(symbols).例
如,我的机器看起来会像这样:
# echo 'main(){printf("hello world/n");}' | gcc -E -v -
Reading specs from /usr/bin/../lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-0202
09/specs
gcc version 2.9-aix51-020209
/usr/bin/../lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/cpp -lang-c -v
-iprefix /usr/bin/../lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/ -D__GN
UC__=2 -D__GNUC_MINOR__=9 -D_IBMR2 -D_POWER -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D
_AIX51 -D_LONG_LONG -D_IBMR2 -D_POWER -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX51
-D_LONG_LONG -Asystem(unix) -Asystem(aix) -D__CHAR_UNSIGNED__ -D_ARCH_COM -
GNU CPP version 2.9-aix51-020209
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/../../../../pow
erpc-ibm-aix5.1.0.0/include
/usr/bin/../lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/include
/opt/freeware/GNUPro/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/../../
../../powerpc-ibm-aix5.1.0.0/include
/opt/freeware/GNUPro/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/includ
e
/usr/include
End of search list.
The following default directories have been omitted from the search path:
/opt/freeware/GNUPro/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/2.9-aix51-020209/../../
../../include/g++-3
/opt/freeware/GNUPro/include
End of omitted list.
# 1 ""
main(){printf("hello world
");}
#
通过编译程序文件的方式来测试编译器是否正常工作。
C编译器的测试
执行如下命令:
#cd /tmp
#vi testc.c
testc.c内容如下:
#include <stdio.h>
main()
{
printf("/nGCC is OK!/n/n");
}
编译test.c
# gcc -O test.c -o test
生成可执行文件test(通过ls命令可以看到)
运行 test
#./test
屏幕输出
GCC is OK!
说明GCC程序编译正确。
初学,有不正确的地方请指出,希望能共同提高。
原文:http://www.loveunix.net/viewthread.php?tid=7325&highlight=gcc