Linux n bin grub boot dev etc home
Linux纵览 n 文件系统的多级树状目录结构 / bin grub boot dev etc home lib lost+found bin proc local man 1 php. 1 usr share src var … … …
Linux终端
Linux终端使用基础 n 什么是Shell? Shell Applications Operation. System Hard. Ware
n shell的种类 : n /bin/sh n /bin/bash 2 n /bin/ash n /bin/bsh n /bin/tcsh
GCC 具
gcc简介 n 名称: – GNU project C and C++ Compiler – GNU Compiler Collection n 管理与维护 – GNU项目 n 基本使用格式 – $ gcc [ 选项 ] <文件名>
编译多个文件 n 文件清单 greeting. h my_app. c #if def _GREETING_H #include <stdio. h> #define _GREETING_H #include "greeting. h" void greeting (char * name); #define N 10 #endif int main(void) greeting. c #include <stdio. h> { char name[N]; #include "greeting. h" printf("Your Name, Please: "); void greeting (char * name) scanf("%s", name); { greeting(name); printf("Hello %s!rn", name); return 0; } }
编译多个文件 n 目录结构(1) greeting. h – 编译命令 . / greeting. c my_app. c n$ n gcc my_app. c greeting. c –o my_app 目录结构(2) – 编译方式(1) greeting. h. / functions greeting. c my_app. c n $gcc my_app. c functions/greeting. c –o my_app -I functions
make 具
使用make 具 n 目标的依赖关系 my_app gcc my_app. o greeting. o -o my_app. o gcc –c my_app. c –I functions my_app. c greeting. o gcc -c functions/greeting. h functions/greeting. c
使用make 具 n Makefile示例 Makefile文件 1 my_app: greeting. o my_app. o 2 gcc my_app. o greeting. o -o my_app 3 greeting. o: functions/greeting. c functions/greeting. h 4 gcc -c functions/greeting. c 5 my_app. o: my_app. c functions/greeting. h 6 gcc –c my_app. c –I functions
使用make 具 n 更实用的Makefile文件 1 OBJS = greeting. o my_app. o 2 CC = gcc 3 CFLAGS = -Wall -O –g 4 my_app: ${OBJS} 5 ${CC} ${OBJS} -o my_app 6 greeting. o: functionsgreeting. c functionsgreeting. h 7 ${CC} ${CFLAGS} -c functionsgreeting. c 8 my_app. o: my_app. c functionsgreeting. h 9 ${CC} ${CFLAGS} -c my_app. c –I functions
Kdevelop 具
调试举例 greeting. h my_app. c #if def _GREETING_H 1 #include <stdio. h> #define _GREETING_H 2 #include "greeting. h" void greeting (char * name); 3 #define N 10 #endif 4 int main(void) n 源文件 greeting. c 5 { #include <stdio. h> 6 char name[n]; #include "greeting. h" 7 printf("Your Name, Please: "); void greeting (char * name) 8 scanf("%s", name) { 9 greeting(name); printf("Hello %! s!rn", name ); printf("Hello rn"); 10 return 0; } 11 } ;
动态调试举例 对静态调试中的例子继续进行动态调试 n 具: gdb 启动命令 n 启动gdb n 启动提示 $gdb GNU gdb Red Hat Linux (5. 3 post-0. 20021129. 18 rh) 启动完毕 Copyright 2003 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i 386 -redhat-linux-gnu". (gdb)
动态调试举例 n 调试指定程序(. /my_app) 加载调试程序 启动调试程序 (gdb) file. /my_app Reading symbols from. /my_app. . . done 程序输出 (gdb) run 提示信息 Starting program: /home/tom/shell_script/cpp/my_app Your Name, Please: tom Hello ! Program exited normally. (gdb) – 问题: n 期望的输出和实际输出不一致
n n n n (gdb) list my_app. c: 1, 20 动态调试举例 #include <stdio. h> 1 2 3 4 5 6 7 8 9 10 11 查看源代码 #include "greeting. h" 设置断点 #define N 10 int main(void) 提示信息 { char name[N]; printf("Your Name, Please: "); scanf("%s", name); greeting(name); return 0; } (gdb) break 7 n Break. Point 1 at 0 x 8048384: n 在程序第 7行设置断点 – 命令: (gdb) break 7 file my_app. c, line 7.
动态调试举例 1 (gdb) run 2 3 Starting program: /home/tom/shell_script/cpp/my_app Breakpoint 1,main() at my_app. c: 7 n 错误详细定位 4 7 5 (gdb) next 6 8 7 (gdb) next 8 Your Name, Please: tom 9 9 printf("Your Name, Please: "); scanf("%s", name); greeting(name); 启动调试程序 断点激活 步进下一步