为什么 clang 不使用预编译头文件?

问题描述

// 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 添加到上面的第二行不会显示任何内容。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...