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


边栏推荐
- RAC delete damaged disk group
- Rhcsa 04 - process management
- 软件设计文档示例模板 - 学习/实践
- Talking about what a high-quality little red book copy needs to have
- 6-4 vulnerability exploitation SSH banner information acquisition
- Flutter 调用高德地图APP实现位置搜索、路线规划、逆地理编码
- Can closed data be deleted by DBCA? can
- Longest increasing subsequence problem (do you really know it)
- MySQL JDBC编程
- Test cs4344 stereo DA converter
猜你喜欢

技术管理 - 学习/实践

RPC - grpc simple demo - learn / practice
![[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

Niuke Xiaobai monthly race 49

Distributed cap theory

Talking about JVM

20000 words will take you to master multithreading

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

Balloon punching and Boolean operation problems (extremely difficult)

戳气球和布尔运算问题(巨难)
随机推荐
Flutter ‘/usr/lib/libswiftCore.dylib‘ (no such file)
Kivy教程之 更改背景颜色(教程含源码)
Kivy教程之 07 组件和属性绑定实现按钮button点击修改label组件(教程含源码)
MySQL JDBC编程
GUI 应用:socket 网络聊天室
Maui introductory tutorial series (5.xaml and page introduction)
Deep understanding of redis -- bloomfilter
Kivy教程之 格式化文本 (教程含源码)
优秀的测试/开发程序员是怎么修炼的?该往哪走......
在代码中使用度量单位,从而生活更美好
Zhengzhou zhengqingyuan Culture Communication Co., Ltd.: seven marketing skills for small enterprises
附件四:攻击方评分标准.docx
牛客小白月赛49
Redis: operation command for collecting set type data
QT qtableview data column width adaptation
Kivy教程之 自定义字体(教程含源码)
[cloud native] those lines of code that look awesome but have a very simple principle
Experience sharing of epidemic telecommuting | community essay solicitation
【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
戳气球和布尔运算问题(巨难)