4
我在頭文件header.h:如何使用.pch和clang?
#define TEST_VALUE 1
#define TEST_STRING "hello world"
和源文件source.cpp:
#include "header.h"
#include "stdio.h"
int main() {
printf(TEST_STRING"\n");
}
我已經按照clang pch article和執行:
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
所以我無法與PCH鏈接,但我可以編譯/鏈接源代碼頭。 與鏗鏘的文章的例子唯一的區別是我已經嘗試過C++,它的描述爲c。 所以我試圖指定C++語言:
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
一個更嘗試用指定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,因爲我能編譯/鏈接clang -I. source.cpp -o source
並且包含路徑(應該)相同。
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
HM,它不應該是'鐺++'和'的#include'或'#include '? –
PeterT
2014-11-05 11:51:22
我剛剛試過編譯頭文件,並用'clang ++'和'cstdio'鏈接 - 沒有運氣。獲得相同的錯誤 – 4ntoine 2014-11-05 11:54:03
首先,不要使用'-cc1'這種方式 - 只需將您的命令行和'clang - ### -c -o test.cc'作爲任何自定義'test.cc'。有很多缺失的內部標誌。 – 2014-11-05 12:47:15