GCC(GNU Compiler Collection)是一个重要的编译器。在linux系统中,GCC是一项核心工具,被用于编译和构建大量开源软件。因此,检查Linux上的GCC版本是一项非常重要的任务。
下面是一些方法来检查Linux上的GCC版本。
方法一:使用Terminal命令
使用Terminal命令是最常用的方法来检查Linux上的GCC版本。请按照以下步骤操作:
步骤1:打开Terminal窗口。您可以按下Ctrl + Alt + T快捷键或从开发者菜单中选择Terminal应用程序。
步骤2:在Terminal中输入以下命令:
“`
gcc –version
“`
该命令将返回GCC版本号。
例如:
“`
$ gcc –version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
…
“`
上面的输出指示GCC的版本为7.4.0。
如果GCC未安装在您的系统上,,则该命令将显示以下错误:
“`
The program ‘gcc’ is currently not installed. You can install it by typing:
sudo apt-get install gcc
“`
步骤3:如果您有多个版本的GCC安装在您的系统上,则可以使用以下命令来查看所有安装的GCC版本:
“`
dpkg -l | grep gcc
“`
该命令将返回已安装的GCC版本列表。
例如:
“`
$ dpkg -l | grep gcc
ii gcc-4.8-base:amd64 4.8.5-4ubuntu2~18.04 amd64 GCC, the GNU Compiler Collection (base package)
ii gcc-7-base:amd64 7.4.0-1ubuntu1~18.04.1 amd64 GCC, the GNU Compiler Collection (base package)
“`
在上面的输出中,您可以看到两个安装的GCC版本基础包的名称。
方法二:使用/proc/version文件
/proc/version文件包含操作系统的版本和GCC版本的信息。您可以使用cat命令查看该文件。
步骤1:打开Terminal窗口。
步骤2:在Terminal中输入以下命令:
“`
cat /proc/version
“`
该命令将返回您的操作系统的版本和GCC的版本。
例如:
“`
$ cat /proc/version
Linux version 5.4.0-74-generic (buildd@lgw01-amd64-063) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #83-Ubuntu P Sat May 8 02:35:39 UTC 2023
“`
上面的输出指示GCC的版本为7.5.0。
方法三:使用命令ls命令查看GCC的安装路径
在Linux中,运行安装文件时,给GCC设置一个默认路径进行安装是非常常见的做法。所以,我们可以通过查看安装路径的方法得知GCC的版本。
步骤1:打开Terminal窗口。
步骤2:在Terminal中输入以下命令:
“`
ls /usr/bin/gcc*
“`
该命令将返回GCC的安装路径。您可以从路径中查看版本号。
例如:
“`
$ ls /usr/bin/gcc*
/usr/bin/gcc /usr/bin/gcc-10 /usr/bin/gcc-ar-10 /usr/bin/gcc-nm-10 /usr/bin/gcc-ranlib-10
“`
上面的输出指示GCC的版本为10。
结论
在Linux中,有许多方法可以检查GCC版本。在这篇文章中,我们介绍了三种最简单的方法。您可以根据需要选择使用哪种方法。希望这篇文章对您有所帮助。
相关问题拓展阅读:
- 如何查看程序被哪个版本编译器编译的linux-gcc
- 怎么查看arm-linux-gcc版本
- red hat linux下查看gcc版本命令
如何查看程序被哪个版本编译器编译的linux-gcc
strings xxx |grep GCC
那是不可能的,除非你加入了调试信息,也行或脊就是编译的时候加入了-g参数,然后用gdb调试就可以显示。更大程度上查看一个elf文件信息。
{档渗
readelf -Wa a.out | head
readelf -wi a.out
readelf -p .comment a.out
objdump -s –section .comment audioplayer
}
如下:
# readelf -Wa bin/gzip
复制代团旁码
ELF Header:
Magic: 7f 45 4c
Class: ELF32
Data: 2’s complement, little endian
Version: (current)
OS/ABI:UNIX – System V
ABI Version:
Type: EXEC (Executable file)
Machine:ARM
Version:x1
Entry point address: 0xa080
Start of program headers:(bytes into file)
Start of section headers:444 (bytes into file)
Flags: 0x, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers:(bytes)
Number of program headers:
Size of section headers:(bytes)
Number of section headers:
Section header string table index: 24
Section Headers:
NameTypeAddr Off Size ES Flg Lk Inf Al
NULL
.note.ABI-tag NOTE0080f4 0000fA
.initPROGBITS0c 00 AX
.textPROGBITSfcfc 00 AX
__libc_freeres_fn PROGBITSe1c 17fe1c 000fAX
__libc_thread_fre PROGBITSd3c 180d3c 0000e4 00 AX
.finiPROGBITSe20 180eAX
.rodataPROGBITSe28 180e A
__libc_subfreeres PROGBITSe0f70 1d8fc 00 A
__libc_atexit PROGBITSe0fcc 1d8fccA
__libc_thread_sub PROGBITSe0fd0 1d8fdA
.ARM.extabPROGBITSe0fd8 1d8fd8 001bA
.ARM.exidxARM_EXIDXe2adc 1daadc 006ea8 00 AL
.tdataPROGBITSf1984 1e WAT
.tbssNOBITSf199c 1e199cWAT
.init_arrayINIT_ARRAYf199c 1e199cWA
.fini_arrayFINI_ARRAYf19a0 1e19aWA
.jcrPROGBITSf19a8 1e19aWA
.data.rel.ro PROGBITSf19ac 1e19ac 00002c 00 WA
.gotPROGBITSf19d8 1e19dc 04 WA
.dataPROGBITSf1a58 1e1af7 00 WA
.bssNOBITSf2350 1e234fWA
__libc_freeres_pt NOBITSf6b78 1e234f 00003c 00 WA
.ARM.attributes ARM_ATTRIBUTESe234f 00002b 1
.shstrtabSTRTAB0000 1e237a
Section to Segment mapping:
Segment Sections…
.ARM.exidx
.note.ABI-tag .init .text __libc_freeres_fn __libc_thread_freeres_fn .fini .rodata __libc_subfreeres __libc_atexit __libc_thread_subfreeres .ARM.extab .ARM.exidx
.tdata .init_array .fini_array .jcr .data.rel.ro .got .data .bss __libc_freeres_ptrs
.note.ABI-tag
.tdata .tbss
Attribute Section: aeabi
File Attributes
Tag_CPU_name: “5TE”
Tag_CPU_arch: v5TE
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-1
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align8_needed: Yes
Tag_ABI_align8_preserved: Yes, except leaf SP
Tag_ABI_enum_size: int
Tag_unknown_44: 1 (0x1)
复制代码
How to retrieve the GCC version used to compile a given ELF executable?
QUES: I’d like to retrieve the GCC version used to compile a given executable. I tried readelf but didn’t get the information. Any thoughts?
ANS: To complete what others have said: it’s not stored in the object (or exe) file, unless you compile with debugging information! (option -g). If you compile with debug info, you can get it back with readelf:
复制代码
# gcc a.c
# readelf -wi a.out
# gcc a.c -g
# readelf -wi a.out
The section .debug_info contains:
Compilation Unit @ offset 0x0:
Length:
Version:
Abbrev Offset: 0
Pointer Size: 8
: Abbrev Number: 1 (DW_TAG_compile_unit)
DW_AT_stmt_list : 0
DW_AT_high_pc : 0x400453
DW_AT_low_pc : 0x400448
DW_AT_producer : GNU C 4.1.(Red Hat 4.1.2-55)
DW_AT_language :(ANSI C)
DW_AT_name: a.c
DW_AT_comp_dir : /work/farsight/test
: Abbrev Number: 2 (DW_TAG_subprogram)
DW_AT_external : 1
DW_AT_name: main
DW_AT_decl_file : 1
DW_AT_decl_line : 4
DW_AT_prototyped : 1
DW_AT_type:
DW_AT_low_pc : 0x400448
DW_AT_high_pc : 0x400453
DW_AT_frame_base :(location list)
: Abbrev Number: 3 (DW_TAG_base_type)
DW_AT_name: int
DW_AT_byte_size : 4
DW_AT_encoding :(signed)
复制代码
ANS2:
怎么查看arm-linux-gcc版本
arm-gcc -v
arm-linux-gcc -v
没看懂你想表物销册达斗碧什么罩宏 不过一般打 arm-linux-gcc –version 以及 arm-linux-gcc -v 可以看到大部分信息。
arm-gcc -v
red hat linux下查看gcc版本命令
gcc -verison
gcc -v
gcc -h
应该都禅亩有显示版本号吧贺歼森
再或者用rpm命令查看囖
rpm -q gcc
man gcc 一样有。。
慢慢试囖改闹。
直接gcc
之缓备后应该扰塌毁会在终端下弹出一个菜单,上面有一系列的命令以及命令作用的解释!
我用的是UBUNTU,说实话没用过 red hat 不过应该是一样的衫扒
gcc -dumpversion
lpm -qa | grep gcc
这个可以显示机上安装GCC的所有版本
关于linux gcc版本检查的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。