12

For the following 3 compile cases :

gcc -o helloc hello.c                    (1)

g++ -o hellocpp hello.cpp                (2)

c++ -o hellocpp hello.cpp                (3)

how do I know the "default include directories", "default link directories" and "default link libraries" in each case ? I am using gcc 4.5.2 in a 32 bit Ubuntu 11.04 environment.

For case (1), is gcc using the standard C libraries or the GNU C libraries ? Is there difference between the two C libraries ?

Comparing cases (2) and (3), is there any difference in the "default link libraries" used by the compiler ? Are they using the standard C++ libraries or the GNU C++ libraries ? What is the difference between the two C++ libraries ?

Thanks in advance for any suggestion.

Lawrence Tsang

user1129812
  • 2,859
  • 8
  • 32
  • 45

3 Answers3

16

Say gcc -v, or g++ -v to print out verbose information about the environment.

E.g. for me this says:

#include <...> search starts here:
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/../../../../include/c++/4.6.2
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/../../../../include/c++/4.6.2/i686-pc-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/../../../../include/c++/4.6.2/backward
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/include
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/include-fixed
 /usr/include

Also try gcc -dumpspecs to see details about the invoked tools in the tool chain.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • 8
    This needs a file to compile. So just running `g++ -v` wont work. It needs to be `g++ -v somefile.cpp` – Baruch Aug 07 '17 at 06:05
  • 4
    As an [alternative](https://stackoverflow.com/a/17940271/287933) you can try `echo | gcc -E -Wp,-v -`. – Machta Nov 20 '17 at 15:22
12

Kerrek SB's answer doesn't quite work for me on Ubuntu 12.04, but this seems to work:

cpp -v

Toward the bottom I get this:

#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
Tom
  • 18,685
  • 15
  • 71
  • 81
0

As another alternative you can use this command:

echo | gcc -E -Wp,-v -

Since messages of gcc are printed as stderr you may redirect it to stdin for further processing (e.g. sed, grep, awk, ...)

echo | gcc -E -Wp,-v - 2>&1 | grep lib
abu_bua
  • 1,361
  • 17
  • 25