This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
How to use pre-compiled headers with gcc version 3.2.2
- From: "lapo_pasqui\ at libero\ dot it" <lapo_pasqui at libero dot it>
- To: "gcc-help" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 8 Oct 2003 17:53:08 +0200
- Subject: How to use pre-compiled headers with gcc version 3.2.2
Hi guys,
I?ve a problem in using pre-compiled headers with gcc version 3.2.2.
As the project I?m working on is getting bigger and bigger, the time needed to
build it is incredibly long.
This is mainly because of the header files containing a few class/ templates
definition.
Therefore I taught to use a few precompiled headers with no luck at all.
According to the online documentation
[http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html] I should give the
gcc a header file to get a precompiled header with .gch extension.
However I get the following error
> gcc -c foo.h
gcc: compilation of header file requested
Looking further at the documentation, I should provide the compiler the ?x
switch as a hint to the compiler about the syntax to be used.
I?m happy with this solution and this is what I get
> gcc -c -x c foo.h
> file foo.o
foo.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
Surprisingly a get an object file. Is this correct?
(What is the format of a precompiled header? Is it an object file or something
else -a text file-?)
Furthermore the extension of the file is not correct (it should be *.gch)
So, I tried to rename the .o file
> gcc -c -x c foo.h ?o gch
and to put it in the same directory as the foo.h file.
However the compiler (or the preprocessor?) does not look at it and prefers the
.h file instead.
gcc -E -v foo.c ?c
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cpp0 -lang-c -v -D__GNUC__=3
-D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=2 -D__GXX_ABI_VERSION=102 -D__ELF__
-Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__
-D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386
-Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ foo.c
GNU CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include
/usr/include
End of search list.
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"
# 1 "foo.h" 1
# 2 "foo.c" 2
What am I doing wrong?
Any help would be appreciated
Lapo