一:linux系統下的交叉編譯基礎。linux
二:安裝GCC:c++
(1):GCC的概述:GCC原名GNU C語言編譯器,後擴展至又能夠處理c++,Fortran,Pascal,Java,以及Ada與其餘語言.vim
[root@server1 dengzhaoxu]# rpm -qa|grep gcc //顯示如下信息表示已經安裝. gcc-4.8.5-36.el7.x86_64 gcc-gfortran-4.8.5-36.el7.x86_64 libgcc-4.8.5-36.el7.x86_64 gcc-c++-4.8.5-36.el7.x86_64 [root@server1 dengzhaoxu]#
(2):安裝GCC:架構
1:鏡像文件:函數
2:掛載光盤到 iso:this
3:製做用於安裝的yum源文件.url
[root@server1 dengzhaoxu]# mkdir /iso //建立鏡像文件 mkdir: 沒法建立目錄"/iso": 文件已存在 [root@server1 dengzhaoxu]# mount /dev/cdrom /iso //掛載光盤到iso下.注意/iso與前方須有空格. mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@server1 dengzhaoxu]# cat /etc/yum.repos.d/dvd.repo //這裏是查看步驟3:能夠使用vim來建立該安裝yum源文件.
#/etc/yum.repos.d/dvd.repo
#or for ONLY the media repo,do this:
#yum --disablerepo=\* --enablerepo=c6-media [command]
[dvd]
name=dvd
baseurl=file:///iso
gpgcheck=0
enabled=2
[root@server1 dengzhaoxu]#
[root@server1 dengzhaoxu]# yum info gcc //查看相關信息
已加載插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repository 'dvd': Error parsing config: Error parsing "enabled = '2'": invalid boolean value
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
已安裝的軟件包
名稱 :gcc
架構 :x86_64
版本 :4.8.5
發佈 :36.el7
大小 :37 M
源 :installed
來自源:anaconda
簡介 : Various compilers (C, C++, Objective-C, Java, ...)
網址 :http://gcc.gnu.org
協議 : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and
: LGPLv2+ and BSD
描述 : The gcc package contains the GNU Compiler Collection version 4.8.
: You'll need this package in order to compile C code.
[root@server1 dengzhaoxu]# yum clean all //安裝前須先要清除
#yum install gcc -y //安裝.
(三):使用GCC:spa
[root@server1 dengzhaoxu]# vim hello.c //編寫c語言程序.(源文件) [root@server1 dengzhaoxu]# gcc hello.c //編譯 [root@server1 dengzhaoxu]# ll hello.c a.out -rwxr-xr-x. 1 root root 8552 4月 13 22:14 a.out //編譯後生成的可執行文件 -rw-r--r--. 1 root root 135 4月 13 22:14 hello.c [root@server1 dengzhaoxu]# ./a.out //運行該文件. hello linux 等趙頊 [root@server1 dengzhaoxu]# ./a.out hello linux d [root@server1 dengzhaoxu]# vim hello.c //修改 [root@server1 dengzhaoxu]# gcc -c hello.c //方式2編譯 [root@server1 dengzhaoxu]# ll hello* -rw-r--r--. 1 root root 148 4月 13 22:16 hello.c -rw-r--r--. 1 root root 1736 4月 13 22:17 hello.o // [root@server1 dengzhaoxu]# gcc -o hello hello.o [root@server1 dengzhaoxu]# ll hello* -rwxr-xr-x. 1 root root 8552 4月 13 22:18 hello //通過多步才生成與源文件同名的可執行文件. -rw-r--r--. 1 root root 148 4月 13 22:16 hello.c -rw-r--r--. 1 root root 1736 4月 13 22:17 hello.o [root@server1 dengzhaoxu]# ./hello hello linux dengzhaoxu 你輸入了:[root@server1 dengzhaoxu]#
2:主程序,子程序連接,子程序的編譯。即在一個程序中調用另外一個程序.插件
[root@server1 dengzhaoxu]# vim first1.c [root@server1 dengzhaoxu]# vim first2.c [root@server1 dengzhaoxu]# gcc -c first1.c first2.c [root@server1 dengzhaoxu]# ll thanks* ls: 沒法訪問thanks*: 沒有那個文件或目錄 [root@server1 dengzhaoxu]# ll first1* -rw-r--r--. 1 root root 106 4月 13 22:36 first1.c -rw-r--r--. 1 root root 1600 4月 13 22:40 first1.o [root@server1 dengzhaoxu]# ll first2* -rw-r--r--. 1 root root 118 4月 13 22:39 first2.c -rw-r--r--. 1 root root 1640 4月 13 22:40 first2.o [root@server1 dengzhaoxu]# gcc -o first first1.o first2.o [root@server1 dengzhaoxu]# ll first* -rwxr-xr-x. 1 root root 8560 4月 13 22:42 first //可執行文件 -rw-r--r--. 1 root root 106 4月 13 22:36 first1.c -rw-r--r--. 1 root root 1600 4月 13 22:40 first1.o -rw-r--r--. 1 root root 118 4月 13 22:39 first2.c -rw-r--r--. 1 root root 1640 4月 13 22:40 first2.o [root@server1 dengzhaoxu]# ./first 在主程序中調用子程序中的函數 執行函數first2 注意函數的的聲明在主程序[root@server1 dengzhaoxu]#
//能夠與上面的進行對照.
[root@server1 dengzhaoxu]# gcc -Wall -c first1.c first2.c // -Wall產生詳細的編譯過程信息.
first1.c: 在函數‘main’中:
first1.c:5:2: 警告:隱式聲明函數‘first2’ [-Wimplicit-function-declaration]
first2();
^
first1.c:6:1: 警告:在有返回值的函數中,控制流程到達函數尾 [-Wreturn-type]
}
^
(4):瞭解makefile的基本語法與變量;code