结对编程项目作业2-开发环境搭建过程
装LINUX下的C语言编译工具GCC
1.下载GCC 到http://gcc.gnu.org 或 在 http://www.sfxce.com/gear.html 下寻找官方链接。
//原gear.html 页面已经删除,请访问 http://ftp.gnu.org/ 官方FTP站寻找最新版本
2.解压
命令:tar jxvf gcc-4.1-20051230.tar.bz2
我解压到/test/tool/gcc
/*根据个人所好选择解压位置,本例中解压至/test/tool/gcc(gcc为重命名的文件夹gcc-4.1-20051230)*/
3. 在根目录下建/test/bin/gcc
/*根据个人所好选择安装位置的地方,本例中安装至/test/bin/gcc*/
4. 配置
配置是由/test/tool/gcc/下的configure来完成的。其命令格式为:
{解压文件路径}/configure --prefix={安装地点路径} [其它选项]
如我们安装到/test/bin/gcc
在机器上这样做的:
[root@mytest /]# cd test/tool/gcc
[root@mytest gcc]#./configure --prefix=/test/bin/gcc
--enable-threads=posix --disable-checking --enable--long-long
--host=i386-redhat-linux --with-system-zlib
--enable-languages=c,c++,java
命令行开始滚动一行行的数据,等停下来就下一步
/*将GCC安装在/test/bin/gcc目录下,支持C/C++和JAVA语言,其它选项参见GCC提供的帮助说明。*/
5. 编译
[root@mytest /]# make
很长时间才能编译完,要有耐心约用40分钟(可能更长 巨长)吧,只有等待。
6. 安装
执行下面的命令将编译好的库文件等拷贝到/test/bin/gcc目录中
(根据你设定的路径,可能需要管理员的权限)这才是真正的安装:
[root@mytest /]# make install
7.链接
gcc、g 、gcj的设置
要想使用GCC的gcc等命令,简单的方法就是用符号连接的方式把它连接到/user/bin 目录下:
[root@mytest /]# cd /usr/bin
[root@mytest bin]# ln -s /test/bin/gcc/bin/gcc gcc
[root@mytest bin]# ln -s /test/bin/gcc/bin/g g
[root@mytest bin]# ln -s /test/bin/gcc/bin/gcj gcj
/*这样,就可以分别使用gcc、g、gcj命令来分别快速编C、C++ 、JAVA的程序了。*/
8.Test
代码如下:
#include <stdio.h>
main()
{
printf("A girl called Jin/n");
}
[root@localhost root]# cd /test
[root@localhost test]# ls
bin box gcc-build img lost+found teach test.c tool used
[root@localhost test]# gcc test.c -o jin
[root@localhost test]# ls
bin box gcc-build img jin lost+found teach test.c tool used
[root@localhost test]# ./jin
A girl called Jin /*成功了*/
[root@localhost test]#
注意:gcc默认权限是任何用户