当前位置:网站首页>简单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


边栏推荐
- Exploration and practice of eventbridge in the field of SaaS enterprise integration
- Balloon punching and Boolean operation problems (extremely difficult)
- Flutter ‘/usr/lib/libswiftCore.dylib‘ (no such file)
- Unity中RampTex介绍和应用: 溶解特效优化
- 每日刷题记录 (十二)
- What is context?
- leetcode:1314. Matrix area and [2D prefix and template]
- Network - vxlan
- Acwing game 58
- 【MATLAB】MATLAB 仿真数字基带传输系统 — 双极性基带信号(第 I 类部分响应波形)的眼图
猜你喜欢

Deep parsing structured exception handling (SEH) - by Matt Pietrek

技术管理 - 学习/实践

附件六:防守工作簡報.docx

最长递增子序列问题(你真的会了吗)
![[Yugong series] go teaching course 001 in July 2022 - Introduction to go language premise](/img/f2/3b95f53d67cd1d1979163910dbeeb8.png)
[Yugong series] go teaching course 001 in July 2022 - Introduction to go language premise

Change the background color of Kivy tutorial (tutorial includes source code)

Kivy教程之 格式化文本 (教程含源码)

Annexe VI: exposé sur les travaux de défense. Docx

The five pictures tell you: why is there such a big gap between people in the workplace?

Talking about JVM
随机推荐
YoloV6实战:手把手教你使用Yolov6进行物体检测(附数据集)
Talking about JVM
更优雅地远程操作服务器:Paramiko库的实践
Kivy教程之 07 组件和属性绑定实现按钮button点击修改label组件(教程含源码)
Network equipment emergency response Guide
Utiliser des unités de mesure dans votre code pour une vie meilleure
我们认为消费互联网发展到最后,依然会局限于互联网行业本身
附件二:攻防演练保密协议.docx
Operate the server remotely more gracefully: the practice of paramiko Library
Unity中RampTex介绍和应用: 溶解特效优化
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Rhcsa 04 - process management
【MATLAB】MATLAB 仿真数字带通传输系统 — ASK、 PSK、 FSK 系统
6-4 vulnerability exploitation SSH banner information acquisition
Rhcsa 01 - create partitions and file systems
Self sharing of a graduate
【MATLAB】MATLAB 仿真模拟调制系统 — FM 系统
CRS-4013: This command is not supported in a single-node configuration.
Kivy教程之 格式化文本 (教程含源码)
Cmake compilation option setting in ros2