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


边栏推荐
- 关于solidworks standard无法获得许可 8544问题的总结
- The five pictures tell you: why is there such a big gap between people in the workplace?
- leetcode:1314. 矩阵区域和【二维前缀和模板】
- 【MATLAB】MATLAB 仿真 — 模拟调制系统 之 AM 调制过程
- YoloV6实战:手把手教你使用Yolov6进行物体检测(附数据集)
- 6-5漏洞利用-SSH弱口令破解利用
- Definition of DCDC power supply current
- Deep parsing structured exception handling (SEH) - by Matt Pietrek
- How do good test / development programmers practice? Where to go
- 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
猜你喜欢

RAC delete damaged disk group

rac删除损坏的磁盘组

appliedzkp zkevm(13)中的Public Inputs

Use units of measure in your code for a better life

拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
![[cloud native] those lines of code that look awesome but have a very simple principle](/img/6d/220c51a643263f431fb57c97c4b8ff.png)
[cloud native] those lines of code that look awesome but have a very simple principle

6-5 vulnerability exploitation SSH weak password cracking and utilization

Redis: hash type data operation command

MySQL JDBC编程
随机推荐
@Feignclient comments and parameters
1. Mx6u-alpha development board (simulating STM32 drive development experiment)
How to view installed r packages in R language
【MATLAB】MATLAB 仿真 — 窄带高斯白噪声
DCDC电源电流定义
Developing mqtt access program under QT
电子元器件商城与数据手册下载网站汇总
Kivy教程之 07 组件和属性绑定实现按钮button点击修改label组件(教程含源码)
Keysight n9320b RF spectrum analyzer solves tire pressure monitoring scheme
Rhcsa 08 - automount configuration
Cmake compilation option setting in ros2
Formatted text of Kivy tutorial (tutorial includes source code)
Definition of DCDC power supply current
Zhengzhou zhengqingyuan Culture Communication Co., Ltd.: seven marketing skills for small enterprises
6-5 vulnerability exploitation SSH weak password cracking and utilization
网络设备应急响应指南
附件2-2保密承诺书.docx
【MATLAB】MATLAB 仿真模拟调制系统 — AM 已调信号的功率谱与相干解调
RPC - grpc simple demo - learn / practice
【MATLAB】MATLAB 仿真数字带通传输系统 — ASK、 PSK、 FSK 系统