当前位置:网站首页>Simple g++ and GDB debugging
Simple g++ and GDB debugging
2022-07-04 04:57:00 【Lzg_ na】
List of articles
1. The build process
| step | effect | command |
|---|---|---|
| Preprocessing | Macro expansion , The header file contains | g++ -E test.cpp -o test.i |
| compile | Generate assembly statement code | g++ -S test.i -o test.s |
| assembly | Generate machine language code | g++ -c test.s -o test.o |
| link | Generate executable files | g++ test.o -o test.exe |
2. g++ Important parameter
| Parameters | effect | command |
|---|---|---|
| -g | Can be gdb debugging | g++ -g test.cpp -o test.exe |
| -O[n] | Code optimization | g++ -O2 test.cpp -o test.exe |
-l | Specify dynamic and static library files | g++ -lglog test.cpp -o test.exe |
| -L | Specify the dynamic and static library file path | g++ -L/home/lzg -lmytest test.cpp -o test.exe |
| -Wall | Print alarm information | g++ -Wall test.cpp -o test.exe |
| -w | Turn off the alarm message | g++ -w test.cpp -o test.exe |
| -std=c++11 | Specify compilation criteria | g++ -std=c++11 test.cpp -o test.exe |
| -D | Specify macro name | g++ -DV5PLAT test.cpp -o test.exe |
-I | Appoint include File path | g++ -DV5PLAT test.cpp -o test.exe |
3、 Generate library files

3.1 Static library
1. Generate binaries
g++ -c swap.cpp -o swap.o -I../include
2. Archive as static library
ar rs libSwap.a swap.o
3. Compile with static library main
g++ main.cpp -lSwap -Lsrc -Iinclued -o main.exe
4. Run the executable
./main.exe
To be sure :
1、-Lsrc Is to execute the path of the static library file , Instead of specifying the source code path
2、-lSwap Do not link static libraries with complete static library names (lib*.a) Write it in
3.2 Dynamic library
1. Generate binaries
g++ -c swap.cpp -I../include -fPIC -shared -o libSwap.so
2. Archive as static library
ar rs libSwap.a swap.o
3. Compile with static library main
g++ main.cpp -lSwap -Lsrc -Iinclued -o main.exe
4. Run the executable
LD_LIBRARY_PATH=src ./main.exe
You need to indicate the path of the dynamic library .
4. gdb debugging
gdb Debugging needs to be added at compile time -g Parameters , Ability to support gdb debugging .
gdb file
ctrl -x ctrl -a
or :
gdbtui file


边栏推荐
猜你喜欢

Correct the classpath of your application so that it contains a single, compatible version of com. go

Unity中RampTex介绍和应用: 溶解特效优化

Can closed data be deleted by DBCA? can

Kivy教程之 更改背景颜色(教程含源码)

在代码中使用度量单位,从而生活更美好

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

MySQL JDBC programming

抓包整理外篇fiddler———— 会话栏与过滤器

如何构建属于自己的知识引擎?社群开放申请

ADB tools
随机推荐
Wobo Union ended its strategic evaluation and decided to retain Bozi's business with excellent performance
【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
红队视角下的防御体系突破之第二篇案例分析
中职组网络安全—内存取证
《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记
First knowledge of batch processing
记几个智能手表相关芯片 蓝牙芯片 低功耗
【MATLAB】MATLAB 仿真模拟调制系统 — FM 系统
6-4 vulnerability exploitation SSH banner information acquisition
LeetCode136+128+152+148
【Go】数据库框架gorm
加密和解密
What should a novice pay attention to when looking for an escort
MySQL indexes and transactions
Annex 4: scoring criteria of the attacker docx
令人头痛的延时双删
MySQL JDBC programming
海力士EMMC5.0及5.1系列对比详解
附件二:攻防演练保密协议.docx
Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it