Slow compilation time with predefined header Boost + GCC +

Launch: gcc version 4.2.1 (build of Apple Inc. 5664)

I created an Apple Xcode project with a precompiled default header. It seems very slow, and the trivial main file with the main function no does not include any code, it takes 6 seconds to compile, and this is after I upgraded to a new SSD drive. I am on a laptop, but I have reservations that upgrading to a workstation will alleviate my problem. If I turn off the precompiled header, then the main file will be compiled in less than a second. Using the precompiled header seems to impose a fine on all files. This delay forces me to avoid compiling and experimenting with code that is not good. Here is what I include in my precompiled header:

#pragma once #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <valarray> #include <vector> #include <boost/smart_ptr/scoped_ptr.hpp> #include <boost/smart_ptr/scoped_array.hpp> #include <boost/smart_ptr/shared_ptr.hpp> #include <boost/smart_ptr/shared_array.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <boost/smart_ptr/weak_ptr.hpp> #include <boost/smart_ptr/intrusive_ptr.hpp> #include <boost/regex.hpp> #include <boost/thread.hpp> #include <boost/bind/bind.hpp> #include <boost/bind/apply.hpp> #include <boost/bind/protect.hpp> #include <boost/bind/make_adaptable.hpp> #include <boost/asio.hpp> //#include <boost/asio/ssl.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/random.hpp> #include <boost/lexical_cast.hpp> #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/local_time/local_time.hpp> #include <boost/date_time/time_zone_base.hpp> #include <boost/circular_buffer.hpp> #include <boost/accumulators/accumulators.hpp> #include <boost/accumulators/statistics.hpp> 

I did not include a spirit that really increases compilation time.

+6
source share
1 answer

GCC precompiled headers work in a very specific way. In any source file, only one precompiled header file can be used. Use -H to indicate whether this header file uses a precompiled version or not.

In addition, you must compile the header file with the same compiler flags as its source file.

A typical way to set up a PCH environment is as follows:

main.cpp:

 #include "allheaders.hpp" int main() { /* ... */ } 

allheaders.hpp:

 #include <algorithm> // ... everything you need 

Compilation:

 g++ $CXXFLAGS allheaders.hpp # 1 g++ $CXXFLAGS -H -c -o main.o main.cpp # 2 g++ $LDFLAGS -o myprogram main.o # 3 

After step 1, you should get the allheaders.hpp.gch file, which should be quite large. In step 2, the -H flag should contain additional output that tells you that a precompiled header file is being used. Step 3 links the executable file.

The idea is that step number 1 can take a very long time, but step number 2 should be much faster.

+7
source

Source: https://habr.com/ru/post/917670/


All Articles