Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to print all the GCC environment variables(path for include directory, library) from the command line, i.e something similar to 'printenv' that gives all bash environment variables ?

share|improve this question
up vote 1 down vote accepted

Usually, one uses gcc -v for this.

gcc -v without any file to compile gives only the compile-time configuration of GCC as well as its default target architecture but when you give it a file to compile (gcc -v test.c), it displays more information. Here is an output example:

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

Of course, it works with other wrappers such as g++.

share|improve this answer
gcc -print-search-dirs

will output the various lists of directories which gcc uses for binaries: its installation directory, the directories where it searches for programs, the directories where it searches for libraries.

echo | gcc -v -E -

will output the actual path variables (COMPILER_PATH, LIBRARY_PATH) and the directories which gcc uses for header files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.