PCH creation in the presence of linker flags

Ian Lance Taylor iant@google.com
Tue Feb 23 18:28:00 GMT 2010


Cesar Strauss <cstrauss@cea.inpe.br> writes:

> Consider a simple header file like:
>
> echo "extern int test;" > test.h
>
> For generating a precompiled header, I find both methods below to work:
>
> gcc -c test.h
> gcc test.h
>
> If, however, I happen to use a linker flag on the command line:
>
> gcc -Wl,-s -c test.h
> gcc -Wl,-s test.h
>
> then, the first method works, but the second one (without -c) gives
> the following error:
>
> /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o: In function
> _start':
> /build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115:
> undefined reference to `main'
> collect2: ld returned 1 exit status
>
> Is this supposed to work?

No.

Normally if you compile a .h file, gcc will not invoke the linker.
Also, when you use the -c option, gcc will not invoke the linker.
However, when you use an explicit -Wl option, and you do not use -c,
then gcc will invoke the linker, and running the linker on a
precompiled header does not work.

Ian



More information about the Gcc-help mailing list