如何在Linux下的C++文件使用GDB调试
2024-09-05 02:38:28
首先在Linux下写好一个.Cpp的文件。
#include<stdio.h>
#include<stdlib.h>
using namespace std;
void show(int arr[], int size)
{
for (int i = ; i < size; ++i)
{
cout << arr[i] << " ";
}
cout << endl;
}
void reverse(int arr[], int size)
{
for (int i = ; i < size ; ++i)
{
int temp = arr[i];
arr[i] = arr[size - - i];
arr[size - - i] = temp;
cout << "第" << i + << "次输出" << endl;
for (int i = ; i < size; ++i)
{
cout << arr[i] << " ";
}
cout << endl;
cout << "------------------------------------" << endl; }
}
int main()
{
int arr[] = { };
for (int i = ; i < ; ++i)
arr[i] = (i + ) * ;
show(arr, );
reverse(arr, );
show(arr, );
system("pause");
return ;
}
在Linux下写完这个程序,我们需要在命令行对C++文件编译。
/*在Xshell中编译,在Linux环境下*/
g++ -o main main.cpp
/*可以使用更简单的,直接g++ main.cpp,这样生成的文件就是a.out*/
编译完成后,我们要启动GDB调试工具,命名为gdb + 要调试程序的程序名,在本例中使用命令为【gdb main】。
做完这一步我们就可以gdb的命令了...
最新文章
- .NET Core的日志[1]:采用统一的模式记录日志
- MyBatis通过JDBC生成的执行语句问题
- web前端之HTML的前世今生
- JDBC删除表数据
- SQL SERVER连接、合并查询
- du -sg 和df -g 所看的文件系统大小不一致
- Python eclipse开发环境搭建
- (转) ICCV 2015:21篇最火爆研究论文
- hdu 3585 二分+最大团
- TFS代码签入指导
- [React] React Fundamentals: Using Refs to Access Components
- Windows7 QT5.6.0(64位)使用mysql(64位)环境搭建详解
- Java GC机制和对象Finalize方法的一点总结
- Delphi对WM_NCHITTEST消息的处理
- 3DMax的OFusion插件使用问题
- windows rt 扫描二维码
- Python:当你遇到了the package “public”?
- 中国居民18位身份证号验证方法,Java算法实现
- bash 3
- JAVA记录-POST与GET方式区别
热门文章
- spark | 手把手教你用spark进行数据预处理
- HotSpot的类模型(2)
- 线程基础知识01-Thread类,Runnable接口
- finally 关键字
- C++输出三角图形
- 数据可视化之powerBI技巧(十六)采悟:PowerBI作图技巧:动态显示可视化标题
- How to install chinese input method
- [Cordova]Cordova6.x自定义插件之Andorid
- It is indirectly referenced from required .class files错误查找的解决办法如下
- Cyber Security - Palo Alto Firewall V-Wires