Compiling with Code:Blocks and MinGW32
2 years, 8 months ago
Since I am somewhat allergic to installing Visual Studio, I went to compile Handmade Hero on Code:Blocks (http://www.codeblocks.org/) and the MinGW GCC Compiler. I choose Code:Blocks because I want to use the graphical debugger (no command line gdb, thanks) as a substitute to Visual Studio's. I think this is important for people to have an alternative (LLVM is unfortunately not ready yet).
And it works, in 32 bits at least.
Disclaimer : This is the minimum to do in order to compile and run. It's a bit dirty. There is a lot of remaining work regarding compilation options and code clean-ups. I wish this was the starting point for seasoned C developers. I wish CMuratory would take a look at the modifications and clean the code for a more robust multi-platform support. Feel free to experiment, and improve this recipe.
1. Downloads and Installations
1.1. Download the following bits :
- codeblocks-13.12mingw-setup.exe (http://sourceforge.net/projects/c...s/codeblocks-13.12mingw-setup.exe)
- DXSDK_Jun10.exe (http://www.microsoft.com/en-us/download/details.aspx?id=6812)
- sal.h (copy-paste from http://research.microsoft.com/en-...jects/invisible/include/sal.h.htm)
- the Handmade Hero source code for day 20 (yeah, it was there when I started)
1.2. Install codeblocks-13.12mingw-setup.exe, use the default options
1.3. Install or unzip DXSDK_Jun10.exe, we only need the DXSDK\Include and DXSDK\Lib\x86 directories
1.4. Unzip handmade_hero_day_020_source.zip where you want to work with it
2. Configure Code:Blocks for the project
2.1. Run Code:Blocks
2.2. Create a new empty project. Create the project inside the Handmade Hero sources.
For example, if you unzipped the sources as E:\handmade (this directory contains the file license.txt), use :
- Project title: handmade
- Folder : E:\
the resulting filename should be: E:\handmade\handmade.cbp
Use default options (GNU GCC etc).
2.3. Add files to the project : handmade.cpp, handmade.h, win32_handmade.cpp and win32_handmade.h
2.4. Modify build options
Right-click on handmade project -> Build Options. Select "handmade" on the top-left.
In Compiler settings -> #defines, add:
In Linker settings -> Link libraries, add: winmm
In Search directories -> Compiler, add the path to DXSDK\Include and the directory to sal.h
In Search directories -> Linker, add the path to DXSDK\Lib\x86 and to the MinGW libs from the Code:Blocks install (for me it's E:\CodeBlocks\MinGW\lib)
2.5. Modify project options
In Build targets, for both targets (Debug and Release), choose Type: GUI application, and deselect all .h files from the build target files.
3. Fix the code
3.1. Because defines in win32_handmade.cpp are used in handmade.h, move them to the top of handmade.h (this is the whole section from "TODO(casey): Implement sine ourselves" to "typedef double real64;")
3.2. The three DEBUG functions are declared as static ; GCC doesn't want it, so simply remove the "internal" from the front of them, both from declarations in handmade.h and from definitions in win32_handmade.cpp
3.3. xinput.h doesn't include the defintion of __in, __out macros, but dsound.h does it, so exchange their include order : put the include for dsound.h first before xinput.h
3.4. GCC doesn't include intrinsics by default, so add them with the right include:
3.5. MinGW doesn't know _snprintf_s, so we'll translate it with a macro:
#define _snprintf(a,b,...) snprintf(a,b,__VA_ARGS__)
Note : I see in http://msdn.microsoft.com/fr-fr/library/f30dzcf6.aspx that the definition of _snprintf_s has a third parameter named count. How do Visual Studio compiles without this parameter ?
It builds. It runs. The sound and my Xbox pad work just fine. It even runs in the debugger.
There are still a lot of warnings, through.
Merry Christmas everyone!