I'm having header file header.h:
#define TEST_VALUE 1
#define TEST_STRING "hello world"
and source file source.cpp:
#include "header.h"
#include "stdio.h"
int main() {
printf(TEST_STRING"\n");
}
I've followed clang pch article and performed:
MBA-Anton:pch asmirnov$ clang -cc1 ./header.h -emit-pch -o ./header.pch
MBA-Anton:pch asmirnov$ clang -cc1 -include-pch header.pch source.cpp -o source
error: C99 was enabled in PCH file but is currently disabled
1 error generated.
MBA-Anton:pch asmirnov$ clang -I. source.cpp -o source
MBA-Anton:pch asmirnov$ ls
header.h header.pch source source.cpp
MBA-Anton:pch asmirnov$ ./source
hello world
So i can't link with PCH but i can compile/link source+header. The only difference with clang article's example is i've tried c++ and it's described for c. So i've tried to specify c++ language:
MBA-Anton:pch asmirnov$ clang -cc1 ./header.h -emit-pch -o ./header.pch2 -x c++
MBA-Anton:pch asmirnov$ clang -cc1 -include-pch header.pch2 source.cpp -o source2 -x c++
source.cpp:2:10: fatal error: 'stdio.h' file not found
#include "stdio.h"
^
1 error generated.
MBA-Anton:pch asmirnov$ ls -l
total 496
-rw-r--r-- 1 asmirnov wheel 56 5 ноя 15:31 header.h
-rw-r--r-- 1 asmirnov wheel 112564 5 ноя 15:50 header.pch
-rw-r--r-- 1 asmirnov wheel 116236 5 ноя 15:50 header.pch2
-rwxr-xr-x 1 asmirnov wheel 8456 5 ноя 15:42 source
-rw-r--r-- 1 asmirnov wheel 80 5 ноя 15:32 source.cpp
One more attempt with specifying c++11:
MBA-Anton:pch asmirnov$ clang -cc1 ./header.h -emit-pch -o ./header.pch3 -x c++ -std=c++11
MBA-Anton:pch asmirnov$ clang -cc1 -include-pch header.pch3 source.cpp -o source3 -x c++ -std=c++11
source.cpp:2:10: fatal error: 'stdio.h' file not found
#include "stdio.h"
^
1 error generated.
MBA-Anton:pch asmirnov$ ls -l
total 728
-rw-r--r-- 1 asmirnov wheel 56 5 ноя 15:31 header.h
-rw-r--r-- 1 asmirnov wheel 112564 5 ноя 15:50 header.pch
-rw-r--r-- 1 asmirnov wheel 116236 5 ноя 15:54 header.pch2
-rw-r--r-- 1 asmirnov wheel 117132 5 ноя 15:57 header.pch3
-rwxr-xr-x 1 asmirnov wheel 8456 5 ноя 15:42 source
-rw-r--r-- 1 asmirnov wheel 80 5 ноя 15:57 source.cpp
I'm not trying to add -I since i'm able to compile/link with clang -I. source.cpp -o source
and include paths are (should be) the same.
PS.
MBA-Anton:pch asmirnov$ clang --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
clang++
and#include <stdio.h>
or#include <cstdio>
? – Venuticlang++
and withcstdio
- no luck. getting the same error – Bounded-cc1
this way - just compare your command line andclang -### -c -o test.cc
for any customtest.cc
. There is a lot of missing internal flags. – Aptitudeclang -### -c -o test.cc
and add there the essential flag-include-pch
. Or try your short command-line without-cc1
at all. – Aptitude