0
// test.hpp
#include <iostream>

// test.cpp
#include "test.hpp"    
int main(){std::cout << "hello world" << std::endl;}

Let's precompile header:

clang++ -c test.hpp 

Let's use the header

clang++ test.cpp -H

Output shows it is not using the header, as no ! appears before test.hpp (like it does with 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

Why is this?

programmer
  • 41
  • 6

1 Answers1

0

This (seems to) work:

clang++ -x c++-header test.hpp -o test.hpp.pch
clang++ -include test.hpp test.cpp

The option -H appears not to be used in clang++ as adding -H to the second above line displays nothing.

programmer
  • 41
  • 6