I am building a lot of auto-generated code, including one particularly large file (~15K lines), using a mingw32 cross compiler on linux. Most files are extremely quick, but thi
Related to @Goz and @Josh_Kelley, you can get gcc/g++ to spit out the preprocessed source (with #includes inline) using -E. That's one way to determine just how large your source is.
And if the compiler itself is the problem, you may be able to strace the compile command that's taking a long time to see whether there's a particular file access or a specific internal action that's taking a long time.
What slows g++ down in general are templates. For example Boost loves to use them. This means nice code, great performances but poor compiling speed.
On the other hand, 15min seems extremely long. After a quick googling, it seems that it is a common problem with mingw
Another process to try is to add "progress marker" pragma
s to your code to trap the portion of the code that is taking a long time. The Visual Studio compiler provides #pragma message()
, although there is not a standard pragma for doing this.
Put one marker at the beginning of the code and a marker at the end of the code. The end marker could be a #error
since you don't care about the remainder of the source file. Move the markers accordingly to trap the section of code taking the longest time.
Just a thought...
I'd use #if 0
/ #endif
to eliminate large portions of the source file from compilation. Repeat with different blocks of code until you pinpoint which block(s) are slow. For starters, you can see if your #include
's are the problem by using #if 0
/ #endif
to exclude everything but the #include
's.
One thing to watch during the compile is how much memory your computer has free. If the compiler allocates so much memory that the computer starts swapping, compile time will go way, way up.
If you see that happen, an easily solution is to install more RAM... or just split the file into multiple parts that can be compiled separately.
Won't give all the details you want, but try running with the -v
(verbose) and -ftime-report
flags. The latter produces a summary of what the compiler has been up to.