![bash命令打印gcc环境变量](https://linux22.com/image/82284/bash%E5%91%BD%E4%BB%A4%E6%89%93%E5%8D%B0gcc%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F.png)
有没有办法从命令行打印所有 GCC 环境变量(包含目录、库的路径),即类似于提供所有 bash 环境变量的“printenv”?
答案1
gcc -print-search-dirs
将输出用于二进制文件的各种目录列表gcc
:其安装目录、搜索程序的目录、搜索库的目录。
echo | gcc -v -E -
将输出实际的路径变量(COMPILER_PATH
, )和用于头文件的LIBRARY_PATH
目录。gcc
答案2
通常,人们会使用gcc -v
它。
gcc -v
没有任何要编译的文件仅给出 GCC 的编译时配置及其默认目标体系结构,但是当您给它一个要编译的文件 ( gcc -v test.c
) 时,它会显示更多信息。这是一个输出示例:
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.9.3/work/gcc-4.9.3/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo Hardened 4.9.3 p1.2, pie-0.6.3' --enable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --disable-libcilkrts --enable-lto --without-cloog --disable-libsanitizer
Thread model: posix
gcc version 4.9.3 (Gentoo Hardened 4.9.3 p1.2, pie-0.6.3)
COLLECT_GCC_OPTIONS='-v' '-std=c99' '-mtune=generic' '-march=x86-64' '-fPIE' '-pie' '-fstack-protector-all' '-fstack-check=specific'
/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/cc1 -quiet -v temp/test.c -fno-strict-overflow -quiet -dumpbase test.c -mtune=generic -march=x86-64 -auxbase test -std=c99 -version -fPIE -fstack-protector-all -fstack-check=specific -o /tmp/ccwQZMEg.s
GNU C (Gentoo Hardened 4.9.3 p1.2, pie-0.6.3) version 4.9.3 (x86_64-pc-linux-gnu)
compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.3-p4, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include
/usr/local/include
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include-fixed
/usr/include
End of search list.
GNU C (Gentoo Hardened 4.9.3 p1.2, pie-0.6.3) version 4.9.3 (x86_64-pc-linux-gnu)
compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version 3.1.3-p4, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: da252983f7bfc7ab5e95ccebc7bbd0c6
COLLECT_GCC_OPTIONS='-v' '-std=c99' '-mtune=generic' '-march=x86-64' '-fPIE' '-pie' '-fstack-protector-all' '-fstack-check=specific'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/bin/as -v --64 -o /tmp/ccn4nThi.o /tmp/ccwQZMEg.s
GNU assembler version 2.25.1 (x86_64-pc-linux-gnu) using BFD version (Gentoo 2.25.1 p1.1) 2.25.1
COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/:/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/:/usr/libexec/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c99' '-mtune=generic' '-march=x86-64' '-fPIE' '-pie' '-fstack-protector-all' '-fstack-check=specific'
/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/collect2 -plugin /usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/lto-wrapper -plugin-opt=-fresolution=/tmp/ccXQl6Vj.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbeginS.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../.. /tmp/ccn4nThi.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/crtn.o
当然,它可以与其他包装器一起使用,例如g++
。