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

C++ 如何知道用于构建linux的gcc版本?,c++,c,linux,gcc,openwrt,C++,C,Linux,Gcc,Openwrt,我使用OpenWRT。这是一个针对嵌入式系统的linux发行版 我想知道用于编译linux的gcc版本 我在网上做了一些研究,但没有结果 我尝试在linux OpenWRT中对一些现有的二进制文件执行这些命令(比如wget) 没有任何结果 是否有办法知道使用gcc构建整个linux(用户空间和内核空间)?对于程序,如果您的系统使用ELF,它会出现在ELF可执行文件的.comment部分 $ cat main.c int main() { } $ gcc main.c $ objdump -s -

我使用OpenWRT。这是一个针对嵌入式系统的linux发行版

我想知道用于编译linux的gcc版本

我在网上做了一些研究,但没有结果

我尝试在linux OpenWRT中对一些现有的二进制文件执行这些命令(比如wget)

没有任何结果


是否有办法知道使用gcc构建整个linux(用户空间和内核空间)?

对于程序,如果您的系统使用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. 主要警告
.comment
部分是可选的。当可执行文件被捆绑到一个包中时,许多发行版会将其从可执行文件中剥离。该部分将放在单独的调试包中

例如,在我的系统上:

$ 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
为了构建OpenWRT工作区,使用了主gcc:

gcc --version
对于交叉编译,所有需要的工具都位于openwrt构建目录下

编译期间使用的gcc可以在OpenWRT的
暂存目录中找到。转到openwrt主目录,在staging目录下查找
工具链
目录。在这里,您将找到一个
bin
目录,所有交叉编译工具都位于该目录中。 例如,对于
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

内核还是用户空间程序?无法确定使用哪个gcc构建“整个linux”。每个可执行文件都可能是用不同的gcc构建的,甚至是可执行文件中的一个库也是用一个gcc构建的,或者它可能根本不是一个C程序(C++、Fortran、Java(带有gcj)等等)。不管怎样,
cat/proc/version
都帮助了我(+1)找出用于构建内核的gcc,我认为它与用于为OpenWRT@MOHAMED:我没有注意到
-a
。无论如何,您的二进制文件可能已被剥离,您必须从调试文件获取版本。在哪里可以找到调试文件?@MOHAMED:这取决于发行版。它们不一定存在,也可能不存在于所有包中。 $ 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 $ 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.
gcc --version
$ ./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