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


边栏推荐
- How do good test / development programmers practice? Where to go
- 2022年6月总结
- Binary search tree
- Leetcode 121 best time to buy and sell stock (simple)
- MySQL JDBC编程
- 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
- 6-4漏洞利用-SSH Banner信息获取
- 【MATLAB】通信信号调制通用函数 — 带通滤波器
- First knowledge of batch processing
- Asahi Kasei participated in the 5th China International Import Expo (5th ciie) for the first time
猜你喜欢

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

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

1. Mx6u-alpha development board (LED drive experiment in C language version)

附件五:攻击过程简报.docx

Formatted text of Kivy tutorial (tutorial includes source code)

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

戳气球和布尔运算问题(巨难)

最长递增子序列问题(你真的会了吗)

Yolov6 practice: teach you to use yolov6 for object detection (with data set)

Redis: operation command for collecting set type data
随机推荐
Kivy tutorial custom fonts (tutorial with source code)
Talking about what a high-quality little red book copy needs to have
PaddleHub人脸识别方案部署,将训练好的模型在pytchrom中进行部署应用
"Don't care too much about salary when looking for a job", this is the biggest lie I've ever heard
The "functional art" jointly created by Bolang and Virgil abloh in 2021 to commemorate the 100th anniversary of Bolang brand will debut during the exhibition of abloh's works in the museum
Graduation project
【MATLAB】通信信号调制通用函数 — 带通滤波器
Zhengzhou zhengqingyuan Culture Communication Co., Ltd.: seven marketing skills for small enterprises
Redis: order collection Zset type data operation command
ADB tools
Rhcsa 08 - automount configuration
Redis: operation command for collecting set type data
What is context?
CRS-4013: This command is not supported in a single-node configuration.
Create ASM disk through DD
QT qtableview data column width adaptation
附件一:202x年xxx攻防演习授权委托书
MySQL indexes and transactions
How do good test / development programmers practice? Where to go
Intersection traffic priority, illustration of intersection traffic rules