include string header = intolerably slow compile

Started by
3 comments, last by jorgander 14 years, 3 months ago
It's not just <string>, but any STL header. After a bit of research and testing, I found that commenting out all the "#include <X>" lines made it compile instantly like it used to, where X is one of 'list', 'limits', 'string', 'sstream', and so on. Of course, the compilation failed since I had only commented out the include directives and the rest of my code still contained references to the STL classes. But the point is that it failed instantly. Interestingly enough, I uncommented one of the STL include directives, and the compilation time shot up again. It still failed since my code needs all of them to compile correctly, but it took a long time to fail. To summarize: This takes a full two minutes to successfully compile:

#include <list>
#include <limits>
#include <string>
#include <sstream>
#define XML_STATIC
#define XML_UNICODE_WCHAR_T
#include <expat.h>

...



This instantly fails:

//#include <list>
//#include <limits>
//#include <string>
//#include <sstream>
#define XML_STATIC
#define XML_UNICODE_WCHAR_T
#include <expat.h>

...



This takes ~13 seconds to fail:

//#include <list>
//#include <limits>
#include <string>
//#include <sstream>
#define XML_STATIC
#define XML_UNICODE_WCHAR_T
#include <expat.h>

...



I'm using Visual C++ 2008 Express Edition. I work on the project from different locations, and this only happens at one of them.
Advertisement
Have you looked into using precompiled headers? Most of the standard C++ library is implemented using templates, so all the code is in the headers. Every time you compile a source file all those headers need to be parsed, and that takes time.

I assume the two minutes is for a full project build, and not a single file?
Two minutes to just compile one file by right clicking on it in VStudio and selecting "Compile". This happens with every file in the project. I created a new console project with "#include <string>" and an empty main(), but no string objects declared, and it compiled instantly. So I'm pretty sure it's just this one project, I just have no idea what the cause is.

I've looked into precompiled headers, although I'm not using them for this project (yet). As I said I use two different machines to work on the project (home and work) - the slow compile occurs on the machine with more RAM, faster processor, faster hard drives, and almost no other running processes. While the slower PC isn't instant, it doesn't take anywhere near two minutes and has a crapload of browsers, other IDEs, and documents open.
Two minutes is a very long time! I'd say there's definitely some sort of configuration issue going on there, rather than something wrong with your actual code.

Do you have anti-virus on the slow machine? I usually put my source folder into the anti-virus's "exception" list so that it doesn't do real-time scanning of files in there (actually, I usually turn off real-time scanning altogether...)

You could also try compiling the offending file from the command-line to see whether the problem is related to actual compiliation or whether it's an IDE thing.

You could use Process Monitor to try and figure out where it's getting stuck.

You might also try re-installing Visual Studio (though I understand why that would be kind of a last resort...)
Found the cause:

The directories are set up differently between the two PCs I use. For example, the expat library at my home PC is at "C:\Development\libraries\expat-2.0.1\lib", while at my work PC it's at "D:\Development\libraries\expat-2.0.1\lib". Recently I was moving as many project-specific settings as possible into the project properties instead of having them in the source code. So for example, removing "#pragma comment(lib, 'opengl32.lib')" from the source and adding "opengl32.lib" to Configuration Properties -> Linker -> Input -> Additional Dependencies.

Well wouldn't you know it, on my work PC I had put "D:\Development\libraries\expat-2.0.1\lib" in the C/C++ -> Additional Include Directories and removed the same path from the global VStudio include directories since I don't use it for any other project. Since this path isn't the same on my home PC ('D:' at home is my dvd drive, while at work is another hard drive), I'll assume it was taking extra time to search that directory for every include file.

I have moved the include directories out of the project settings and back into the VStudio list, and the files are taking <2 seconds to compile now. Thanks for the replies and helpful ideas, I probably wouldn't have figured it out if I hadn't sat down and gone over every last detail in order to post here.

This topic is closed to new replies.

Advertisement