使用预编译的头文件减少clang编译时间 [英] Decrease clang compile time with precompiled headers

查看:229
本文介绍了使用预编译的头文件减少clang编译时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个数据库项目,该项目将查询(以某种高级语言表示)编译成c ++代码。此代码由数据库编译和执行。那部分工作得很好。

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.

现在,我正在尝试减少C ++查询代码的编译时间。我想知道我是否可以使用预编译的标头来提高性能。

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.

查询被转换为一个名为Query.cpp的文件,该文件包括library / src / Database.hpp。 Database.hpp文件包含更多文件,例如StandardTypes.hpp等。我可以预编译所有这些头文件以加快Query.cpp的编译速度吗?如果是,我该怎么做?到目前为止,我找不到任何预编译标头的好例子,只有一些非常基本的东西。

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.

我使用以下命令来编译Query.cpp:

I use the following command to compile Query.cpp:

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


推荐答案

来创建预编译的头文件,包括您所拥有的所有头文件不要更改为Query.h并使用:

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需要包含Query.h

Query.cpp needs to include Query.h

这篇关于使用预编译的头文件减少clang编译时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆