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)
看gcc的文檔(例如http://gcc.gnu.org/onlinedocs/gcc-4.5.2 /gcc/Precompiled-Headers.html#Precompiled-Headers,但使用與您正在使用的gcc相對應的文檔),它描述瞭如何生成預編譯頭文件(我們不這樣做,實驗表明它在我們的代碼中無利可圖基礎)。 – AProgrammer 2011-02-24 13:46:22
BTW,包括.cpp文件可能是一個錯誤。 – AProgrammer 2011-02-24 13:46:57
@ user506901:'#include「xxx.cpp」'很可怕。 – 2011-02-24 13:50:12