Reputation: 722
On a linux server which has an old version of gcc (4.4.7), I built gcc 7.4.0 from source code and installed it in a directory within the home.
Now I'm not sure how to use it. The directory includes some subdirectories, one named "include". Inside it there is a folder named "c++". It includes another folder named "7.4.0". But where are C header files? Did the installer install them in a different place? Which address should I provide with -I
option when compiling a C program?
Unfortunately I don't have the gcc source directory anymore.
Upvotes: 1
Views: 2216
Reputation: 4012
But where are C header files?
You can find out where gcc expects them by
echo '#include <stdio.h>' | gcc -xc - -H -v -fsyntax-only
The -v
part will print the search paths like
#include "..." search starts here:
#include <...> search starts here:
/home/...
/usr/local/include
...
The -H
part will print which header files art actually being used:
. /usr/include/stdio.h
.. /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
... /usr/include/features.h
etc.
The command line with echo
above can be used if you have no source file handy. In the case you are interested how, say, module.c
behaves, you can use -v
and -H
when compiling that module, e.g.
gcc module.c -H -v -o module.elf
Which address should I provide with
-I
option when compiling a C program?
Paths where headers of your C project are located if they are not in the current directory. For simple projects you do not need -I
: Compiling module.c
will find #include "module.h"
if both files are located in the same directory.
The right option to specify extra system header path would be -isystem
, however an installation is supposed to find the system headers without any further hacking, i.e. the supposed search paths must be listed under #include <...> search starts here:
and without setting -isystem
.
Did the installer install them in a different place?
libc implementations (like glibc or Newlib) are not part of GCC whereas the C++ library libstdc++-v3 is hosted with GCC and is built when GCC is configured with --enable-languages=c++
. The location of the C-libraries and C-headers should be worked out by configure.
For some C-libraries like Newlib, GCC supports in-tree builds so that these target libraries will be contained in the installation and the paths are set appropriately. Building glibc however is much more complicated.
Upvotes: 4