All source files re-compiled after header change

When I modify any header file using Code::Blocks and do a build, mingw re-compiles every .cpp file in the project (and takes about 4 minutes). Is there a way to only compile the one .cpp that was modified? This would drastically reduce development time for me.

You can compile the entire project in four minutes?!?! It takes me like twenty-five!
Also, try right-clicking the file you modified in the list on the left side of the screen. It should give you an option to compile just that file. So long as you do this with every file you alter, it shouldn’t try to redo everything when you hit build.

I’m not sure if there’s a way to force it or not in C::B, but in general it is not safe to do that in C++. The compilers do not have a reliable way of tracing header file dependencies, so the only safe thing to do is a full project rebuild.

You could try to get all the necessary header updates in at the start and then just work in the source after that.

Yea, this does imply that you want to do your header changes and get them right, then work on just source files, but that’s frequently more easily said than done.

Thanks for the input, everyone. I’ll build individual files only if I’m changing spacing or comments, and do a full rebuild otherwise.

I know that Cygwin at least has an option to split the compiling process into multiple threads to enable faster compilation; I don’t know if mingw has that option, but if it does it can cut your compile times by 70-80% I’ve found.

I use ccache to that end. ccache automatically detects if a particular source/header combination was compiled before, and if so, it just uses the previous results. Note that this only helps with local development, and only if you don’t change game.h. Even with ccache, changing game.h will compile 90% of all source files to recompile.

15 minutes to compile here.

I’ve found that Codeblocks is pretty good about only compiling what it needs to compile; however, if you’ve updated from Git, that’ll generally touch enough that it rebuilds everything. Can be worthwhile to pull, compile a fresh master, then recompile as needed when modding.

After some searching through the CodeBlocks documentation I found the split jobs options. Go to your settings page and look for “build options”, then go to “number of build processes” and set it to about 1-1.5x the number of cores you have on your machine. And trust me, it’s well worth the time, the equivalent in Cygwin cut my build times from around 15 min down to like, 2.

That having been said, there are also cleanups we can do to make the project compile faster, they’re also good for keeping the code modular.
Make interfaces (defined in .h files) as small as possible.
Only include files where you have to, prefferably in .cpp files, only in .h files if you really have to.
If you only need to reference a particular class in your methods, you can often just declare it’s existence, e.g.
class item;
int drop_item( item *item_to_drop );

If compilation takes 15 minutes, I recommend not compiling with -O(3, s, whatever you use) while developing. -O0 runs fast enough and is sufficient for testing. Unless compilation takes 15 minutes with -O0, in which case you probably want to buy a machine with a better CPU if you’re looking into doing C++ development for a long-term hobby. =P

THANK YOU SO MUCH!!!
I realize this option has been here the whole time, but it’s a little buried. For clarification, the full path to this setting is Settings->Compiler settings->Build options tab. Here are some before/after numbers.

Processor - Core i5-2500k (Turbo at 4.00 GHz)
“Number of processes for parallel builds” now set to 6

Before:
Release - 3 min, 46s
Debug - 4 mins, 18s

After
Release - 1 min, 5s
Debug - 1 min, 21s