裝LINUX下的C語言編譯工具GCC,下載了不會裝又搜安裝方法
卻都是一種(可能是轉載的 錯誤都一樣)說的很籠統,在這裏我整理了一下
希望剛剛起步的朋友都能用上這款優秀的GNU編程工具。支持一下開源。
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默認權限是任何用戶
GCC安裝教程
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.