clang -include option

Hello all,

I have a question about -include option.
Imagine that I have main.c which depends on mylib1.h and mylib2.h

I can easily compile it using the follow command:
clang -include lib/mylib1.h -include lib/mylib2.h main.c -o

But if I precompile two header: pch**/mylib1.h.pch** and pch**/mylib2.h.pch** and try to use with -include option, it doesn’t work:

clang -include pch/mylib1.h -include pch/mylib2.h main.c -o

:1:10: fatal error: ‘mylib2.h’ file not found
#include “mylib2.h”
^
1 error generated.

Please note that the same works fine for one precompiled header.
Could anybody explain me that behaviour.

Thanks an advance,
Vasily

Hi Vasily:

You can only include one precompiled header per compilation, so the second -include should just include the regular header, but since you changed the path, clang couldn’t find it.

Pretty sure clang pch works just like gcc, so here’s the gcc page which gives a lot more detail:

https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html

hth…
don