C++ Makefile/双重编译

C++ Makefile/双重编译,c++,precompiled-headers,C++,Precompiled Headers,最近我注意到,在其他人扩展了项目之后,编译时间显著增加。我建议使用C++预编译头。include部分被移动到一个单独的文件precompiled.h中 #include <iostream> #include <stxxl/vector> #include <stxxl/priority_queue> #include <stxxl/sort> #include <stxxl/scan> #include <stxxl/stre

最近我注意到,在其他人扩展了项目之后,编译时间显著增加。我建议使用C++预编译头。include部分被移动到一个单独的文件precompiled.h中

#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"
当然,main.cpp文件中的第一行是include precompiled.h。但是,在执行特定于主文件的make file之后,我会得到编译预编译的.h文件警告和与myFile1.cpp myFile1.cpp相关的报告时得到的报告和警告。我猜编译过程是重复的。 我已经读到预编译的头文件与.gch文件相关联,而我并没有生成.gch文件。 非常感谢您在这方面的任何帮助。谢谢

我想将makefile的内容包含在main.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 $@ $(STXXL_LDLIBS)

您需要将precompiled.o:precompiled.h规则更改为precompiled.h.gch:precompiled.h,以便GCC知道它是预编译头

您需要将precompiled.o:precompiled.h规则更改为precompiled.h.gch:precompiled.h,以便GCC知道它是预编译头

例如,查看GCC文档,但是使用与您使用的gcc对应的文档,它描述了如何生成预编译的头文件,我们不这样做,实验表明它在我们的代码库中是无利可图的。顺便说一句,包括.cpp文件可能是一个错误。@user506901:include xxx.cpp很可怕。谢谢。我将包含的.cpp文件重命名为.h文件。但是,再次调用main.cpp文件特定的makefile之后,我会得到相同的报告和警告?应该是这样吗?看看gcc文档,但是使用与您使用的gcc相对应的文档,它描述了如何生成预编译的头文件,我们不这样做,实验表明它在我们的代码基础上是无利可图的。顺便说一句,包含.cpp文件可能是个错误。@user506901:include xxx.cpp很可怕。谢谢。我将包含的.cpp文件重命名为.h文件。但是,再次调用main.cpp文件特定的makefile之后,我会得到相同的报告和警告?应该是这样吗?
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 $@ $(STXXL_LDLIBS)