How do I use gcc, g++, and gdb?

编译与调试(gcc,g++,gdb) Linux中的gcc,g++,gdb的使用方法。 阅读详情

The C compiler on eniac is gcc. Its C++ counterpart is g++.

To compile a C or C++ program:

% gcc file.c

or

% g++ file.c

This compiles file.c into an executable binary named a.out.

Here are a few options to gcc and g++:

-o outputfile
To specify the name of the output file. The executable will be named a.out unless you use this option.
-g
To compile with debugging flags, for use with gdb.
-L dir
To specify directories for the linker to search for the library files.
-l library
This specifies a library to link with.
-I dir
This specifies a directories for the compile to search for when looking for include files.

 


The debugger is gdb. Here is a typical example of a gcc/gdb session:

% cat hello.c
#include<stdio.h>

main() {
    int count;

    for (count=0;count<10;count++)
       printf("Hello from CETS!/n");
}
% gcc -g hello.c
% gdb ./a.out
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.13 (sparc-sun-solaris2.3), 
Copyright 1994 Free Software Foundation, Inc...
(gdb) b main
Breakpoint 1 at 0x10784: file hello.c, line 6.
(gdb) r
Starting program: /home1/b/bozo/./a.out 


Breakpoint 1, main () at hello.c:6
6           for (count=0;count<10;count++)
(gdb) s
7              printf("Hello from CETS!/n");
(gdb) p count
$1 = 0
(gdb) disp count
1: count = 0
(gdb) set count=8
(gdb) s
Hello from CETS!
6           for (count=0;count<10;count++)
1: count = 8
(gdb) 
7              printf("Hello from CETS!/n");
1: count = 9
(gdb) c
Continuing.
Hello from CETS!

Program exited with code 01.
(gdb) q
%

Here are a few gdb commands:

help
Will give you help on most gdb functions. If you wish for help on a specific command, type help command.
b function-name
To set a breakpoint at a function.
r args
To run the program. It will run until it reaches a breakpoint.
s
To single-step through lines of code.
c
To continue until the next breakpoint.
p variable
To print a variable's value.
q
To quit gdb.
gcc/gdb: DWARF/macro 详细的调试信息,带有宏定义 阅读详情

相关推荐

深信服PT1-AF实验考试

深信服PT1-AF实验考试实验练习可以去深信服的在线实验平台(链接如下):深信服在线实验平台 (sangfor.com.cn)实验考试其实就是把所有的每一部分实验综合了起来以下内容仅做参考,不确保一样。

m0_72019240的博客 7116

Linux中gcc、g++、gdb以及make/Makefile的使用

Linux中gcc、g++、gdb以及make/Makefile的使用

m0_53005929的博客 1万+

Unity Acceleratorc与Cache Server unity的缓存服务器

文章目录1.作用概述2.用法(使用,看这个就够了)服务端下载部署Unity Acceleratorc修改http管理端口修改Editor连接端口客户端使用(设置好一次提交设置,团队拉取即可全部生效)3.测试平台切换测试资源导入测试(打开编辑器的情况下)项目启动测试(不打开编辑器的情况下)4.不同版本表现5.服务端监控6.服务端缓存7.冲突8.预警9.不同项目/不同配置-同种资源10.缓存清除 1.作用概述 编辑器模式下,导入资源,切换平台unity都会重新识别资源,大型项目很浪费时间,使用Cache Ser

euphorias的博客 3812

理解g++、GCC、GDB、GNU以及各种后缀

language translate There are 4 phases for a Program to finally get translated into an executable file viz: Preprocessing : It expands the code (For example - expansion of macros, removal of comments and conditional compilation) Compilation : Translates ..

漫步量化 1538

手把手教你用CubeMX给GD32F103点灯、调串口(附完整工程)

本文详细介绍了如何使用CubeMX为GD32F103开发板配置GPIO点灯和串口通信,包含完整的工程创建、代码构建和测试流程。特别强调了GD32与STM32的差异点及常见避坑技巧,帮助开发者快速上手GD32开发。

weixin_42566424的博客 313

华为灵衢UB总线介绍

华为发布"灵衢"(UB)超节点互联协议,旨在构建支持AI大模型计算的基础设施。该协议采用统一内存语义和对等架构,使设备可直接访问远程内存,实现资源池化。技术突破包括2.1微秒超低时延和TB级带宽,支持64节点、52万张昇腾卡的集群互联。相比传统RDMA,"灵衢"更注重系统级资源调度,而非单纯数据传输。华为开放技术规范,推动生态建设,已有厂商开发兼容IP核。"灵衢"可适应x86、RISC-V等架构,未来将扩展至百万卡规模集群。

技术引领业务创新 4425

Linux(六)编译链接、gcc和gdb

本篇文章向大家介绍了编译链接过程,gcc和gdb的安装、使用方法,以及学习创建makefile文件和使用makefile文件,内附带使用截图

SSaltedFish_tian的博客 1605

基于STM32的智能循迹小车设计(基础版)

基于STM32的智能循迹小车设计 硬件准备 1、小车底盘+四直流电机(带轮) 2、STM32F103C8T6核心板 3、12V 8700mAh锂电池(可以用几节18650锂电池) 4、循迹模块 选择的是TCRT500L,五路集成在一起,集成度比较高,但是可能不如五个单独的循迹模块好用 5、L298N电机驱动模块 四驱车为啥用L298N电机驱动模块? 可以把左边的两个电机并联,用输出A控制。把右边的两个电机并联,用输出B控制。 12V供电接电源正极,供电GND接电源负极和核心板GND,5V供电接核心

Rendezvous1的博客 3万+

G++、GDB 学习笔记

1、开发环境的搭建 安装 GCC、GDB sudo apt update # 通过以下命令安装编译器和调试器 sudo apt install build-essential gdb # 以下命令来确认每个软件是否安装成功,如果安装成功,则显示版本号 gcc --version g++ --version gdb --version 安装 CMake sudo apt install cmake # 确认 cmake 是否安装成功 cmake --version 2、GCC 编译器 介

algsup 1202

Python爬虫 汽车之家 车型销量--参数分析与实现

【代码】Python爬虫 汽车之家 车型销量--参数分析与实现。

2201_76125393的博客 850

超详细教程YoloV8官方推荐免费数据集网站Roboflow一键导出Voc、COCO、Yolo、Csv等格式

YoloV8官方推荐了一个数据集网站,就是Roboflow。Roboflow是一个数据集管理平台,提供了免费的数据集,同时也支持上传自己的数据集进行格式转换。使用Roboflow,开发者可以方便地获取所需格式的数据集,无需手动转换格式。此外,Roboflow还提供了多种数据预处理、数据增强等功能,可帮助开发者更好地优化训练数据

Snu77的博客 2万+

【 gcc & gdb】

gcc和gdb用法详解 -c、-o、-Wall、-D、-I、-g list、break、info break、delete、run、continue、ignore、step、finish、q

qq_55805517的博客 1401

AI上推荐 之 NeuralCF与PNN模型(改变特征交叉方式)

1. 前言 随着信息技术和互联网的发展, 我们已经步入了一个信息过载的时代,这个时代,无论是信息消费者还是信息生产者都遇到了很大的挑战: 信息消费者:如何从大量的信息中找到自己感兴趣的信息? 信息生产者:如何让自己生产的信息脱颖而出, 受到广大用户的关注? 为了解决这个矛盾, 推荐系统应时而生, 并飞速前进,在用户和信息之间架起了一道桥梁,一方面帮助用户发现对自己有价值的信息, 一方面让信息能够展现在对它感兴趣的用户前面。 推荐系统近几年有了深度学习的助推发展之势迅猛, 从前深度学习的传统推荐模型(协

Miracle8070 1万+

Linux学习工具之gcc、g++、gdb使用

1、编译一个c程序-o output_file:指定输出的可执行文件名text.c: c源文件名2、示例3、编译c++程序。

2401_83157962的博客 461

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

gcc、 binutils、gdb

目录 1、Binutils工具集 2、区分VMA与LMA 1、Binutils工具集 GNU为GCC编译器提供了配套的辅助工具集(Binutils)) http://www.gnu.org/software/binutils/ addr2line - 将指定地址转换为对应的文件名和行号 - 常用于分析和定位内存访问错误的问题 //f...

洋葱汪的博客 1364

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

CentOS下安装中文输入法、gcc、g++、gdb

CentOS中文、gcc、g++、gdb快捷安装命令

SuLiJuan66的专栏 1337

gcc 和 gdb

gcc 和 gdb 参考视频 gcc是编译器,用于编译c,c++,java等多种语言,生成最后的可执行文件。 gdb是程序调试器。 两者都是由GNU推出的。 gcc部分 gcc的特性:交叉平台编译,就是可以在当前的CPU上编译其他CPU平台上运行的软件,比如,你可以使用Unix的操作系统编译在X86 CPU上运行的代码。 编译过程以及其中的文件后缀约定为: 预处理 编译 汇编 链接 过程 文件后缀 说明 开始编译前 .c C语言源代码文件 .a 由目标文件构成的档案库文件

TROUBLE I AM IN 1413

Linux编译c++(gcc、g++、gdb)以及Windows环境下使用vs code和cmake进行跨平台c++开发、编译32位程序

环境:Ubuntu 16.04 1.安装编译环境: // 以下语句一句一句执行 sudo apt update // 该句执行后同时安装gcc g++ gdb sudo apt install build-essential gdb // 安装完成后分辨输入下面的命令查看版本 gcc --version g++ --version gdb --version // 安装cmake sudo apt install cmake // 安装成功后,输入下面的命令查看版本 cmake --version

dap769815768的博客 2461

linux下的gcc和gdb

gcc gdb cmake

qq_59328991的博客 327

gcc编译器及gdb调试器入门

gcc编译器 概念: *gcc是GNU编译器套件(GNU Compiler Collection),它包括了C、C++、Objective-C、Fortran、Java、Ada和Go语言的前端,也包括了这些语言的库(如libstdc++、libgcj等等)。GCC的初衷是为GNU操作系统专门编写的一款编译器。GNU系统是彻底的自由软件。此处,“自由”的含义是它尊重用户的自由 环境:Linux ...

爱党人士 1492

【原创】GCC选项-g和-ggdb的区别

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33744141的博客 1639

GCC -g OPTION

-gProduce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information. <br />On most systems that use stabs format, -g enables use of extra debugging information that only GDB

JIN RIZE's 研二 872

gcc和gdb教程

Tutorial of gcc and gdb The graphical user interface (GUI) domainates the current operating environments for personal computing. However, there are still tons of powerful tools, such as gcc and gdb,

tkp2014的专栏 1049
上一篇: 作用域模型分析
下一篇: Using g++
Qicz
博客等级 码龄16年 56粉丝 122原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值