2

最近我注意到(在其他人扩展项目之后)编译时间显着增加。有人建议我使用 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"

并且头文件特定的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 -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 $@ $(STXXL_LDLIBS)

当然,主 .cpp 文件中的第一行是“include "precompiled.h"”。但是,在执行主文件特定的 make 文件后,我得到了编译“precompiled.h”文件时得到的报告和警告(与 myFile1.cpp myFile1.cpp 相关的警告和报告)。我猜编译过程是重复的。我读过预编译的头文件与我没有生成的 .gch 文件相关联。对此的任何帮助都将受到高度赞赏。谢谢

我想包含特定于主 .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)
4

1 回答 1

0

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

于 2011-02-27T10:24:06.557 回答