问题描述
// test.hpp
#include <iostream>
// test.cpp
#include "test.hpp"
int main(){std::cout << "hello world" << std::endl;}
让我们预编译头文件:
clang++ -c test.hpp
让我们使用标题
clang++ test.cpp -H
输出显示它没有使用标题,因为没有!出现在 test.hpp 之前(就像使用 g++ 一样):
. ./test.hpp
.. /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/iostream
... /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9/bits/c++config.h
.... /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9/bits/os_defines.h
..... /usr/include/features.h
这是为什么?
解决方法
这(似乎)有效:
clang++ -x c++-header test.hpp -o test.hpp.pch
clang++ -include test.hpp test.cpp
选项 -H 似乎没有在 clang++ 中使用,因为将 -H 添加到上面的第二行不会显示任何内容。