Handmade Hero»Forums»Code
Blake
2 posts
Including Source Files In Another Source File
I'm currently rewriting a personal project to look more like handmade hero's code. I'm very confused about Casey including .cpp files, like #include "handmade_tile.cpp"" inside of handmade.cpp. Is it a temporary solution, or is it the correct way to code in conjunction with inline and static? When I copy this style I get buried in multiple definition and undefined reference errors.

I'm far behind in watching the videos, and I can't find the video where he talks about this specifically. I'm certain that is the reason I'm having so much trouble.
Ville Penttinen
8 posts
Including Source Files In Another Source File
Including CPP (source) files this way is often used in a build method called 'Unity build'. Which has nothing to do with the game engine, but rather it's away to have minimal amount of Translation Units (?) and this can make compilation faster, and in a sense easier because building no longer requires anything but compiling a single (or two in the case of Handmade Hero) file(s).

Basically in C and C++ #include is just copy-pasting the contents of the included file into the file that includes it. Which means this can cause problems in certain cases if you have defined something in a header and then use it across multiple source files. Especially with this build method.

Do note that this way of building is not required, you can just use the more common way with having multiple header & source files compiled separately and then linked together. And then just #include the header files.
Blake
2 posts
Including Source Files In Another Source File
Aaah okay. I've heard of unity builds but didn't realize that's what he was doing in the stream. Everything makes much more sense. Thank you.