2011-02-24 158 views
2

最近我注意到(在其他人扩展了项目之后)编译时间大大增加了。我被建议使用C++预编译头文件。该“包括”部分被移动到一个单独的文件“precompiled.h”Makefile/double编译

#include <iostream> 

#include <stxxl/vector> 
#include <stxxl/priority_queue> 
#include <stxxl/sort> 
#include <stxxl/scan> 
#include <stxxl/stream> 

#include <string> 
#include <sstream> 
#include <cstdlib> 
#include <ctime> 
#include <cmath> 
#include <vector> 
#include <limits.h> 
#include <queue> 
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <fstream>    
#include <cairo.h> 
#include <cairo-pdf.h> 
#include "myFile1.cpp" 
#include "myFile2.cpp" 

和头文件生成文件具体有以下内容:

STXXL_ROOT  ?= /home/mirza/stxxl-1.2.1 
STXXL_CONFIG ?= stxxl.mk 
include $(STXXL_ROOT)/$(STXXL_CONFIG) 

# use the variables from stxxl.mk 

CXX    = $(STXXL_CXX) 
CPPFLAGS  += $(STXXL_CPPFLAGS) 

# add your own optimization, warning, debug, ... flags 
# (these are *not* set in stxxl.mk) 
CPPFLAGS  += $(shell pkg-config --cflags cairo) 
STXXL_LDLIBS += $(shell pkg-config --libs cairo) 

CPPFLAGS  += -O3 -Wall -g -c -DFOO=BAR 

# build your application 
# (my_example.o is generated from my_example.cpp automatically) 

precompiled.o: precompiled.h 
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) precompiled.h -o [email protected] $(STXXL_LDLIBS) 

当然,在主的第一行.cpp文件是“包含”precompiled.h“”。但是,在执行主文件特定的make文件后,我得到编译“precompiled.h”文件(与myFile1.cpp myFile1.cpp相关的警告和报告)时得到的报告和警告。我想编译过程是重复的。 我读过预编译头文件与.gch文件相关联,我没有设法生成这些文件。 任何帮助,这是高度赞赏。谢谢

我想这将是有益的,包括特定于主要.cpp文件的生成文件的内容。也许通过改变这个文件我可以“告诉编译器”加载完成一次。

STXXL_ROOT  ?= /home/mirza/stxxl-1.2.1 
STXXL_CONFIG ?= stxxl.mk 
include $(STXXL_ROOT)/$(STXXL_CONFIG) 

# use the variables from stxxl.mk 

CXX    = $(STXXL_CXX) 
CPPFLAGS  += $(STXXL_CPPFLAGS) 

# add your own optimization, warning, debug, ... flags 
# (these are *not* set in stxxl.mk) 

CPPFLAGS  += $(shell pkg-config --cflags cairo) 
STXXL_LDLIBS += $(shell pkg-config --libs cairo) 


CPPFLAGS  += -O3 -Wall -g -DFOO=BAR 

# build your application 
# (my_example.o is generated from my_example.cpp automatically) 
fileA.bin: fileA.o 
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) fileA.o -o [email protected] $(STXXL_LDLIBS) 
+0

看gcc的文档(例如http://gcc.gnu.org/onlinedocs/gcc-4.5.2 /gcc/Precompiled-Headers.html#Precompiled-Headers,但使用与您正在使用的gcc相对应的文档),它描述了如何生成预编译头文件(我们不这样做,实验表明它在我们的代码中无利可图基础)。 – AProgrammer 2011-02-24 13:46:22

+1

BTW,包括.cpp文件可能是一个错误。 – AProgrammer 2011-02-24 13:46:57

+1

@ user506901:'#include“xxx.cpp”'很可怕。 – 2011-02-24 13:50:12

回答

0

您需要将precompiled.o: precompiled.h规则更改为precompiled.h.gch: precompiled.h这样GCC才能知道它的预编译头