2009-05-24 1 views
28

빠른 질문 - 왜 프리 컴파일 된 헤더를 사용합니까?왜 미리 컴파일 된 헤더 (C/C++)를 사용합니까?

편집 : 응답을 읽기 , 나는 내가 그들과 함께해온 것은 좀 바보 의심 :

#pragma once 

//Defines used for production versions 

#ifndef PRODUCTION 
#define eMsg(x) (x) //Show error messages 
#define eAsciiMsg(x) (x) 
#else 
#define eMsg(x) (L"") //Don't show error messages 
#define eAsciiMsg(x) ("") 
#endif //PRODUCTION 

#include "targetver.h" 
#include "version.h" 

//Enable "unsafe" but much faster string functions 
#define _CRT_SECURE_NO_WARNINGS 
#define _SCL_SECURE_NO_WARNINGS 

//Standard Includes 
#include <stdio.h> 
#include <tchar.h> 
#include <iostream> 
#include <direct.h> 
#include <cstring> 
#ifdef _DEBUG 
#include <cstdlib> 
#endif 

//Standard Template Library 
#include <bitset> 
#include <vector> 
#include <list> 
#include <algorithm> 
#include <iterator> 
#include <string> 
#include <numeric> 

//BOOST libraries 
#include <boost/algorithm/string.hpp> 
#include <boost/lexical_cast.hpp> 
#include <boost/scoped_array.hpp> 

//Windows Includes 
#define WIN32_LEAN_AND_MEAN 
#include <windows.h> 
#include "FILETIME_Comparisons.h" 
#include <shlwapi.h> 
#include <Shellapi.h> 
#include <psapi.h> 
#include <imagehlp.h> 
#include <mscat.h> 
#include <Softpub.h> 
#include <sfc.h> 
#pragma comment(lib, "wintrust.lib") 
#pragma comment(lib,"kernel32.lib") 
#pragma comment(lib,"Psapi.lib") 
#pragma comment(lib,"shlwapi.lib") 
#pragma comment(lib,"imagehlp.lib") 
#pragma comment(lib,"Advapi32.lib") 
#pragma comment(lib,"Shell32.lib") 
#pragma comment(lib,"Sfc.lib") 
#pragma comment(lib,"Version.lib") 

//Crypto ++ Libraries 
#ifdef _DEBUG 
#pragma comment(lib,"cryptlibd.lib") 
#else 
#pragma comment(lib,"cryptlib.lib") 
#endif 
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 
#include <md5.h> 
#include <sha.h> 

//String libraries 
#include "stringUnicodeConversions.h" 
#include "expandEnvStrings.h" 
#include "randomString.h" 
#include "getShortPathName.h" 

//Regular Expression Libraries 
#include "fpattern.h" 

//File Result Record 
#include "unixTimeToFileTime.h" 
#include "fileData.h" 

//Writer 
#include "writeFileData.h" 

//Criteria Structure System 
#include "priorities.h" 
#include "criterion.H" 
#include "OPSTRUCT.H" 
#include "regexClass.H" 
#include "FILTER.h" 

//Sub Programs Root Class 
#include "subProgramClass.h" 

//Global data 
#include "globalOptions.h" 

//Logger 
#include "logger.h" 

//Console parser 
#include "consoleParser.h" 

//Timeout handler 
#include "timeoutThread.h" 

//Zip library 
#include "zip.h" 
#include "unzip.h" 
#include "zipIt.h" 

//Scanner 
#include "mainScanner.h" 
#include "filesScanner.h" 

//Sub Programs 
#include "volumeEnumerate.h" 
#include "clsidCompressor.h" 
#include "times.h" 
#include "exec.h" 
#include "uZip.h" 

//64 Bit support 
#include "disable64.h" 
+3

Visual Studio에서 중요한주의 사항 : 각 헤더의 첫 번째 #include는 #include "stdafx.h"인지 확인하십시오. 그렇지 않으면 파일이 구문 분석되지 않습니다! 바보, 알아. 그러나 만드는 것은 쉬운 실수입니다. – rlbond

+2

보다 구체적으로, 위의 모든 항목은 "stdafx.h"를 포함하여 구문 분석되지 않습니다. http://en.wikipedia.org/wiki/Precompiled_header를 참조하십시오 – rlbond

답변

34

훨씬 빨리 컴파일됩니다. C++ 컴파일은 수년이 필요합니다. 대형 프로젝트에서 언젠가 비교해보십시오!

5

그래서 당신이 그 (것)들에게 당신이 당신의 프로젝트를 빌드 할 때마다 컴파일 할 필요가 없습니다. 그들은 변경되지 않을 시스템 헤더에 사용됩니다.

+0

당신이 말하는 것은 내가 꽤 바보 같았다는 것을 ..... 위의 편집을 읽으십시오 ..... –

5

컴파일 속도가 빨라집니다.

다른 프로젝트의 헤더를 포함하는 경우 변경할 필요가 없습니다. 이것을 미리 컴파일 된 헤더에 넣으면 소스 코드를 변경할 때 해당 코드를 다시 컴파일 할 필요가 없습니다. 이렇게하면 변경되지 않은 코드를 반복적으로 컴파일 할 필요가 없어 컴파일 시간이 단축됩니다.

25

C/C++에서 #include 메커니즘은 현재 파일에 지정된 파일의 텍스트 복사본입니다. 헤더에는 다른 헤더 (다른 헤더 포함)가 포함되므로 #include를 수행하면 각 cpp 파일 (또는 cxx, c, 무엇이든간에)에 수만 줄의 C++가 추가 될 수 있습니다. 매번 컴파일됩니다. 대규모 프로젝트의 경우 병목 현상이 될 수 있습니다.

미리 컴파일 된 헤더는 그들이에 포함 된 CPP에 상태를 컴파일 된 것을 포함하여 다음 번 각 헤더를 컴파일하여이 속도를

+0

실제로 미리 컴파일 된 것을 헤더는 헤더 파일 자체가 번역 단위가 아닙니다. 좋은 설명, 네. – macroland

9

재 :. 현재 사용, 당신은 매우 많은 수의 파일로 대상이있는 경우 , 그런 방법으로 PCH를 사용하는 것이 더 빠를 수도 있습니다. 의존하는 헤더가 많고 빈번하게 변경하는 경우 자주 변경하는 소스 파일의 수가 매우 많으면 PCH 사용으로 인해 재 작성 시간이 단축됩니다.

그러나 일반적인 조언은 변경되지 않는 PCH에만 물건을 넣는 것입니다. PCH 자체를 생산하는 데 일정한 오버 헤드가 있기 때문입니다. 모든 재 구축시마다 (헤더 중 하나를 끊임없이 조정하여)이를 실행하면 PCH를 사용하면 재구성 속도가 느려질 수 있습니다.

+0

그 파일들은 거의 모든 빌드를 변경합니다 : P –