gcc 환경 변수를 인쇄하는 bash 명령

gcc 환경 변수를 인쇄하는 bash 명령

명령줄에서 모든 GCC 환경 변수(디렉토리, 라이브러리를 포함한 경로)를 인쇄하는 방법이 있습니까? 즉, 모든 bash 환경 변수를 제공하는 "printenv"와 유사합니까?

답변1

gcc -print-search-dirs

바이너리에 대한 다양한 디렉터리 목록( gcc설치 디렉터리, 프로그램이 검색되는 디렉터리, 라이브러리가 검색되는 디렉터리)이 출력됩니다.

echo | gcc -v -E -

실제 경로 변수( COMPILER_PATH, )와 LIBRARY_PATH헤더 파일에 사용된 디렉터리가 출력됩니다.gcc

답변2

일반적으로 사람들은 gcc -v그것을 사용합니다.

gcc -vNo file to compile은 단지 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++.

관련 정보