+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
一·编译与调试篇
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
编译
1.vim中文件的保存
:w /root/c/a.c
2.编译时设置输出文件
gcc a.c -o do
3.查看编译过程
gcc -v a.c
4.设置编译的语言
cp a.c a.u
gcc a.u //file not recongnized
gcc -x 'c' a.u //compile sucessfully
5.设置ANSIC标准
gcc -asci a.out
/* gcc 中的很多标准并不被ANSIC所支持*/
6.编译C++程序
g++ a.cpp -o a.out
7.查看文件的相关信息
file aa.out
8.用vim查看文件具体内容
vim a.c
调试
1.使用gdb进行程序调试
gcc -g -o a.debug a.c
/* compile a.c to a.debug(executabe program) */
/* 这个可执行程序加入了供调试所用的信息 */
2.调试程序的过程:
<1> 启动gdb
gdb
<2> 加载需要调试的程序
file a.debug
<3> 设置断点
break 6 //set a breakpoint at Line 6
info breakpoint //look all breakpoint
<4> 按调试模式运行程序
run //start
next
/* the program will continue
and stop at the next line */
continue
/* the program will continue
and stop at the next breakpoint */
step
/* similar to the command "next",but when happen to
the functions the command "next" finish the
call just by one step, otherwise "step"
go into the functions. */
print i // look the value of the variable i
<5>退出gdb
q //exit