【发布时间】:2012-06-13 02:42:34
【问题描述】:
运行:gcc 版本 4.2.1(Apple Inc. build 5664)
我创建了一个带有默认预编译头文件的苹果 XCode 项目。它似乎很慢,一个没有主要功能的琐碎主文件不包含任何代码需要6秒才能编译,这是我升级到新的SSD驱动器之后。我在笔记本电脑上,但我对升级到工作站会缓解我的问题持保留意见。如果我关闭预编译头文件,那么主文件将在一秒钟内编译。似乎使用预编译的标头会对所有文件造成不利影响。这种延迟让我想避免编译和试验不好的代码。这是我在预编译头文件中包含的内容:
#pragma once
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <valarray>
#include <vector>
#include <boost/smart_ptr/scoped_ptr.hpp>
#include <boost/smart_ptr/scoped_array.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/shared_array.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/regex.hpp>
#include <boost/thread.hpp>
#include <boost/bind/bind.hpp>
#include <boost/bind/apply.hpp>
#include <boost/bind/protect.hpp>
#include <boost/bind/make_adaptable.hpp>
#include <boost/asio.hpp>
//#include <boost/asio/ssl.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/random.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/local_time/local_time.hpp>
#include <boost/date_time/time_zone_base.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
我没有包含精神,这确实使编译时间上升。
【问题讨论】:
-
所以一个“没有主要功能的普通主文件不包含代码”比一个包含上面列出的所有包含的项目需要更少的时间来编译?不应该这样吗?
-
另外,我对预编译头文件的理解是,它们只倾向于节省编译时间,否则它们会通过来自多个来源的
includes 重复编译。这不是你的情况,所以我想你使用预编译头文件的编译时间与不使用的情况类似。也就是说,您不会通过使用预编译的标头来获得太多收益。您确实应该将您的包含限制在特定于源文件的基础上。 -
这是什么意思:“这种延迟让我想避免编译和试验不好的代码。”?
标签: c++ gcc boost compilation precompiled