Linux重要命令行摘记_编译与调试篇

本文介绍了如何使用GCC进行C/C++程序的编译,并详细解释了各种编译选项的作用。此外,还深入探讨了如何利用GDB进行有效的程序调试,包括设置断点、查看变量值等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
一·编译与调试篇
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

编译

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值