预编译头与GCC [英] Precompiled headers with GCC

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

问题描述

任何人成功获得预编译头与GCC工作?我没有运气在我的尝试,我没有看到很多很好的例子,如何设置。我试过在cygwin gcc 3.4.4和使用4.0 Ubuntu上。

Anyone had any success getting precompiled headers working with GCC? I have had no luck in my attempts and I haven't seen many good examples for how to set it up. I've tried on cygwin gcc 3.4.4 and using 4.0 on Ubuntu.

推荐答案

我一定有成功。首先,我使用了以下代码:

I have definitely had success. First, I used the following code:


#include <boost/xpressive/xpressive.hpp>
#include <iostream>

using namespace std;
using namespace boost::xpressive;

//A simple regex test
int main()
{
    std::string hello( "hello world!" );

    sregex rex = sregex::compile( "(\\w+) (\\w+)!" );
    smatch what;

    if( regex_match( hello, what, rex ) )
    {
        std::cout << what[0] << '\n'; // whole match
        std::cout << what[1] << '\n'; // first capture
        std::cout << what[2] << '\n'; // second capture
    }
    return 0;
}

这只是一个来自Boost Xpressive的hello世界首先,我用gcc中的 -H 选项编译。它显示了一个巨大的列表头使用它。然后,我看看我的IDE(代码:: blocks)生成的编译标志,并看到这样的:

This was just a hello world from Boost Xpressive (see below for link). First, I compiled with the -H option in gcc. It showed an enormous list of headers that it used. Then, I took a look at the compile flags my IDE (code::blocks) was producing and saw something like this:

g ++ -Wall -fexceptions -g -c main.cpp -o obj / Debug / main.o

所以我写了一个命令来编译Xpressive。 hpp文件具有完全相同的标志:

So I wrote a command to compile the Xpressive.hpp file with the exact same flags:

sudo g ++ -Wall -fexceptions -g / usr / local / include / boost / xpressive / xpressive。 hpp

我用 -H 重新编译了原始代码, :

I compiled the original code again with the -H and got this output:


g++ -Wall -fexceptions -H  -g     -c main.cpp -o obj/Debug/main.o
! /usr/local/include/boost/xpressive/xpressive.hpp.gch
main.cpp
. /usr/include/c++/4.4/iostream
.. /usr/include/c++/4.4/x86_64-linux-gnu/bits/c++config.h
.. /usr/include/c++/4.4/ostream
.. /usr/include/c++/4.4/istream
main.cpp

!!意味着编译器能够使用预编译头。 x意味着它不能使用它。使用适当的编译器标志是至关重要的。我脱掉了-H并进行了一些速度测试。预编译头部从14秒改善到11秒。

The ! means that the compiler was able to use the precompiled header. An x means it was not able to use it. Using the appropriate compiler flags is crucial. I took off the -H and ran some speed tests. The precompiled header had an improvement from 14 seconds to 11 seconds. Not bad but not great.

注意:以下是范例的连结: http://www.boost.org/doc/libs/1_43_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.examples 我无法使其在帖子中工作。

Note: Here's the link to the example: http://www.boost.org/doc/libs/1_43_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.examples I couldn't get it to work in the post.

BTW:我使用以下g ++

BTW: I'm using the following g++

g ++(Ubuntu 4.4.3-4ubuntu5)4.4.3

这篇关于预编译头与GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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