简体   繁体   English

如何知道用于构建linux的gcc版本?

[英]How to know the gcc version used to build the linux?

I use OpenWRT. 我使用OpenWRT。 it's a linux distribution for embedded systems 它是嵌入式系统的Linux发行版

I want to know the gcc version used to compile the linux 我想知道用于编译linux的gcc版本

I made some researchs in the net but without results. 我在网上做了一些研究但没有结果。

I tried to execute these commands for some existing binary in the linux OpenWRT (like wget) 我试图对linux OpenWRT中的一些现有二进制文件执行这些命令(如wget)

strings -a <default binary> | grep "GCC"
strings -a <default binary> | grep "gcc"

But I did not get any result 但我没有得到任何结果

even the 即便是

strings -a  /lib/libgcc_s.so.1 | grep  "gcc"
strings -a /lib/libuClibc-0.9.30.1.so | grep   "gcc"

does not give any result 没有给出任何结果

Are there a way to know used gcc to build the whole linux (For both user space and kernel space)? 有没有办法知道使用gcc构建整个linux(用户空间和内核空间)?

For programs, it appears in the .comment section of ELF executables, if your system is using ELF. 对于程序,如果您的系统使用ELF,它将出现在ELF可执行文件的.comment部分中。

$ cat main.c
int main() { }
$ gcc main.c
$ objdump -s -j .comment a.out

a.out:     file format elf64-x86-64

Contents of section .comment:
 0000 00474343 3a202844 65626961 6e20342e  .GCC: (Debian 4.
 0010 372e322d 35292034 2e372e32 00474343  7.2-5) 4.7.2.GCC
 0020 3a202844 65626961 6e20342e 342e372d  : (Debian 4.4.7-
 0030 33292034 2e342e37 00                 3) 4.4.7.

The compiler used to compile the kernel is available from the string in /proc/version , for example: 用于编译内核的编译器可从/proc/version的字符串获得,例如:

$ cat /proc/version
Linux version 3.8.5 (...) (gcc version 4.7.2 (Debian 4.7.2-5) ) ...

A major caveat 一个重要的警告

The .comment section is optional. .comment部分是可选的。 Many distributions will strip it from the executable when the executable is bundled into a package. 当可执行文件捆绑到包中时,许多发行版将从可执行文件中删除它。 The section will be placed in a separate debug package. 该部分将放在一个单独的调试包中。

For example, on my system: 例如,在我的系统上:

$ objdump -s -j .comment /usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0
/usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0:     file format elf64-x86-64

objdump: section '.comment' mentioned in a -j option, but not found in any input
file

After installing the libcurl3-dbg package, we get an image with the stripped sections by following the GNU debug link: 安装libcurl3-dbg软件包后,我们按照GNU调试链接获取带有剥离部分的图像:

$ objdump -s -j .comment  \
    /usr/lib/debug/.build-id/8c/4ae0ad17a4e76bab47c487047490061bd49de3.debug

/usr/lib/debug/.build-id/8c/4ae0ad17a4e76bab47c487047490061bd49de3.debug:
    file format elf64-x86-64

Contents of section .comment:
 0000 4743433a 20284465 6269616e 20342e37  GCC: (Debian 4.7
 0010 2e322d35 2920342e 372e3200           .2-5) 4.7.2.

For building the OpenWRT workspace your main gcc is used: 为了构建OpenWRT工作区,使用了主要的gcc:

gcc --version

For cross compile all the needed tools are located under you openwrt build dir. 对于交叉编译,所有需要的工具都位于openwrt build dir下。

The gcc used during the compile can be found in the staging directory of OpenWRT. 编译期间使用的gcc可以在OpenWRT的staging directory中找到。 Go to you openwrt home directory and look for the toolchain directory under the staging dir. 转到openwrt主目录并查找staging目录下的toolchain目录。 Here you will find a bin directory, where all the cross-compile tools are located. 在这里,您将找到一个bin目录,其中包含所有交叉编译工具。 For example for ar71xx : 例如对于ar71xx

$ ./staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc --version
mips-openwrt-linux-gcc (OpenWrt/Linaro GCC 4.6-2013.05 r57678) 4.6.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改要在Linux CentOS上与MPI一起使用的默认GCC编译器 - How to change default GCC compiler to be used with MPI on Linux CentOS 使用GCC构建Linux可执行文件 - Build An Linux Executable Using GCC 使用另一个 gcc 版本在 Windows 上构建 gcc - Build gcc on Windows with another gcc version Linux如何知道进程使用了​​多少物理内存? - How does Linux know how much physical memory is used by a process? 如何知道用于在C ++中构建共享库的优化选项 - How to know the optimzation options used to build a shared library in C++ 较低版本的gcc中使用的静态库 - static library used in lower version gcc 如何检查 Linux 操作系统中使用的 C++ 版本? - How to check the C++ version is being used in Linux OS? 如何在目标平台上探测系统版gcc使用的C ++ ABI - How to probe the C++ ABI used by the system version of gcc on the target platform Linux上的编译器(GCC)交叉编译(到Windows)-如何在非源目录中进行编译? - Compilator (GCC) cross-compilation (to windows) on linux - how can I build it in non-source directory? 我怎么知道我应该使用哪个C ++标准版本来构建哪个版本的Boost? - How do I know which C++ standard version I should use to build which version of Boost?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM