当前位置:网站首页>简单g++和gdb调试
简单g++和gdb调试
2022-07-04 03:59:00 【Lzg_na】
1. 编译过程
| 步骤 | 作用 | 命令 |
|---|---|---|
| 预处理 | 宏展开,头文件包含 | g++ -E test.cpp -o test.i |
| 编译 | 生成汇编语句代码 | g++ -S test.i -o test.s |
| 汇编 | 生成机器语言代码 | g++ -c test.s -o test.o |
| 链接 | 生成可执行文件 | g++ test.o -o test.exe |
2. g++重要参数
| 参数 | 作用 | 命令 |
|---|---|---|
| -g | 可被gdb调试 | g++ -g test.cpp -o test.exe |
| -O[n] | 代码优化 | g++ -O2 test.cpp -o test.exe |
-l | 指定动静态库文件 | g++ -lglog test.cpp -o test.exe |
| -L | 指定动静态库文件路径 | g++ -L/home/lzg -lmytest test.cpp -o test.exe |
| -Wall | 打印告警信息 | g++ -Wall test.cpp -o test.exe |
| -w | 关闭告警信息 | g++ -w test.cpp -o test.exe |
| -std=c++11 | 指定编译标准 | g++ -std=c++11 test.cpp -o test.exe |
| -D | 指定宏名 | g++ -DV5PLAT test.cpp -o test.exe |
-I | 指定include文件路径 | g++ -DV5PLAT test.cpp -o test.exe |
3、生成库文件

3.1 静态库
1. 生成二进制文件
g++ -c swap.cpp -o swap.o -I../include
2. 归档为静态库
ar rs libSwap.a swap.o
3. 利用静态库编译main
g++ main.cpp -lSwap -Lsrc -Iinclued -o main.exe
4. 运行可执行文件
./main.exe
需要说明:
1、-Lsrc是为了执行静态库文件的路径,而不是指定源代码路径
2、-lSwap链接静态库时不要把完整静态库名称(lib*.a)写进来
3.2 动态库
1. 生成二进制文件
g++ -c swap.cpp -I../include -fPIC -shared -o libSwap.so
2. 归档为静态库
ar rs libSwap.a swap.o
3. 利用静态库编译main
g++ main.cpp -lSwap -Lsrc -Iinclued -o main.exe
4. 运行可执行文件
LD_LIBRARY_PATH=src ./main.exe
需要注明动态库路径.
4. gdb调试
gdb调试需要在编译时加入-g参数,才能支持gdb调试.
gdb file
ctrl -x ctrl -a
或:
gdbtui file


边栏推荐
- Redis: operation command for collecting set type data
- Can closed data be deleted by DBCA? can
- Self sharing of a graduate
- Balloon punching and Boolean operation problems (extremely difficult)
- Kivy教程之 格式化文本 (教程含源码)
- 【MATLAB】通信信号调制通用函数 — 插值函数
- Kivy教程之 更改背景颜色(教程含源码)
- Correct the classpath of your application so that it contains a single, compatible version of com.go
- PaddleHub人脸识别方案部署,将训练好的模型在pytchrom中进行部署应用
- DCDC电源电流定义
猜你喜欢

Definition of DCDC power supply current

YoloV6实战:手把手教你使用Yolov6进行物体检测(附数据集)

6-5漏洞利用-SSH弱口令破解利用

Use units of measure in your code for a better life

Can closed data be deleted by DBCA? can

qt下开发mqtt的访问程序

MAUI 入门教程系列(5.XAML及页面介绍)

Many founders of technology companies provided enterpriser first with a round C financing of up to US $158million to help it invest in the next generation of global innovators
![leetcode:1314. Matrix area and [2D prefix and template]](/img/b4/2c9e66c8eafe1db2a3d07e861494e0.png)
leetcode:1314. Matrix area and [2D prefix and template]

Rhcsa 04 - process management
随机推荐
Dp83848+ network cable hot plug
Wobo Union ended its strategic evaluation and decided to retain Bozi's business with excellent performance
Kivy教程之 07 组件和属性绑定实现按钮button点击修改label组件(教程含源码)
【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
优秀的测试/开发程序员是怎么修炼的?该往哪走......
【Go】数据库框架gorm
附件一:202x年xxx攻防演习授权委托书
CRS-4013: This command is not supported in a single-node configuration.
软件设计文档示例模板 - 学习/实践
Rhcsa 07 - user and group management
Kivy教程之 格式化文本 (教程含源码)
Precautions for accompanying driving these 23 points should be paid attention to!
PaddleHub人脸识别方案部署,将训练好的模型在pytchrom中进行部署应用
6-4漏洞利用-SSH Banner信息获取
Kivy tutorial custom fonts (tutorial with source code)
Redis: operation command for collecting set type data
更优雅地远程操作服务器:Paramiko库的实践
牛客小白月赛49
附件2-2保密承诺书.docx
MySQL JDBC编程