使用gcc和make调式程序.

一: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