Decrease clang compile time with precompiled heade

2019-07-07 05:09发布

I am working on a database project that compiles queries (expressed in some higher level language) into c++ code. This code is compiled and executed by the database. That part works perfectly fine.

Right now, I am trying to reduce the compile time for the C++ query code. I was wondering whether I can use precompiled headers to gain performance here.

The query is translated into a file called Query.cpp which includes library/src/Database.hpp. The Database.hpp file includes further files like StandardTypes.hpp and so on. Can I precompile all those header files to speed up the compilation of Query.cpp? If yes, how can I do that? I could not find any good example for precompiled headers so far, only some really basic stuff.

I use the following command to compile Query.cpp:

clang++ -fPIC -std=c++11 Query.cpp -I./library/src/ -shared -o libquery.so;

1条回答
够拽才男人
2楼-- · 2019-07-07 05:42

to create pre-compiled header include all the headers you don't change into Query.h and use:

clang -cc1 Query.h -emit-pch -o Query.h.pch

to use the pre-compiled header type:

clang -cc1 -include-pch Query.h.pch Query.cpp -shared -o libquery.so;

Query.cpp needs to include Query.h

查看更多
登录 后发表回答