Author Topic: Guide to compiling, using Libtcod/SDL/CodeBlocks/Mingw64/GCC4.8.1 on Win7/64bit  (Read 11443 times)


  • Rogueliker
  • ***
  • Posts: 99
  • Karma: +0/-0
    • View Profile
    • Email
Using Libtcod/SDL/Code::Blocks/Mingw64/GCC4.8.1 on Win7/64bit

So I decided to switch over to using a 64-bit version of my toolchain for my roguelike in development, as well as moving to C++11, and I encountered a lot of hassle in doing so. So I wrote up some instructions on how to do it. I will at some point put all this up on a webpage somewhere with relevant screenshots.

Let me know if I've missed anything or screwed anything up, or just let me know your thoughts.

1. First, download and install the 64-bit MinGW-builds version of MinGW at:
You want the Web Installer labelled "Download mingw-builds-install.exe (170.0 kB)".
Install this in somewhere like "C:\MINGW64". Please don't use any spaces in the path, as CodeBlocks can't handle spaces very well in library filepaths.
When you are installing, please select the following options:

POSIX threads (to enable C++11 std::threads)
SJLJ debugging (not important AFAIK)

2. When this is done, add c:\MINGW64\bin to the system path (Computer/Properties/Advanced System Settings/Environment Variables). Note when you apply the change, you will have to restart any command prompts, programs etc as the PATH only is read at their startup.

3. Now set up and configure Codeblocks following the instructions given in:

There are a few minor differences however, mainly seemingly in the layout of the latest Mingw (in the Search directiories settings). Here are my settings:

Global Compiler Settings/Toolchain Executibles/Program Files

Compiler's Installation Directory: C:\Mingw64
C Compiler: x86_64-w64-mingw32-gcc.exe (found in C:\Mingw64\bin)
C++ Compiler: x86_64-w64-mingw32-g++.exe (found in C:\Mingw64\bin)
Linker for Dynamic Libs: x86_64-w64-mingw32-g++.exe (found in C:\Mingw64\bin)
Linker for Static Libs: x86_64-w64-mingw32-gcc-ar.exe (found in C:\Mingw64\bin)
Resource Compiler: windres.exe (found in C:\Mingw64\bin)
Make Program: mingw32-make.exe (found in C:\Mingw64\bin)

Global Compiler Settings/Toolchain Executibles/Additional Paths

Add C:\Mingw64\libexec\gcc\x86_64-w64-mingw32\4.8.1 here

Global Compiler Settings/Search Directories/Compiler

Add the following:


Global Compiler Settings/Search Directories/Linker

Add the following:


Global Compiler Settings/Compiler Settings/Other options

Add "-m64"

Now save everything, making sure to "Auto-detect" first. Best to restart code blocks.

4. Now download a 64-bit version of SDL. This can be found at

You want the file "SDL-1.2-20111107-win64.tar.gz"

Extract it to something like C:\SDL so the path is C:\SDL\SDL-1.2-20111107-win64 (for example).

Don't do anything else with this at the moment.

5. Now following the instructions at

down to, but not including, "Compiling libtcod" download the latest Libtcod code to somewhere like C:\libtcod. Don't compile anything yet, we have further changes to do.

5a. Note you may need to download and install MSYS (the version you want is MSYS-1.0.11.exe if you haven't it already to follow the instructions in step 5.

5b. And you may also need TortoiseHg ( if you haven't got it already either. Note that if an error such as "An error occured during the insallation of assembly 'Microsoft.VC90.CRT, version="9.0.30729.1",publikKeyToken-"1fc8b3b9a1e18e3b", processorArchitecture="amd64", type="win32". Please refer to Help and Support for more information. HRESULT:0x80070BC9." occurs, you have outstanding updates/reboots, so you need to reboot your Windows first before installing Tortoise hg 2.4.1 (see for more information).

Note that using the hg clone command will create a libtcod directory inside C:\Libtcod. I've kept the structure of C:\Libtcod\libtcod\ though you may want to squish it to make it neater.

6. Now, before compiling libtcod, we have to copy over compatible 64-bit SDL library and headers. To do this, first create a new directory in C:\Libtcod\libtcod\dependencies called SDL-1.2.20. We're going to duplicate the layout of the existing SDL-1.2.15 directory, only with the updated 64-bit files.

Make a nested subdirectory called include\SDL (for example C:\Libtcod\libtcod\dependencies\SDL-1.2.20\include\SDL) and copy all the header files (*.h) from the equivalent directory in the 64-bit SDL distribution (in my case C:\SDL\SDL-1.2-20111107-win64\include\SDL) into it.

Note that the SDL-1.2.15 directory that comes with Libtcod contains two additional .h files not in the .20 verson - SDL_config_win32.h and SDL_copying.h. No idea if these are needed, but I copied these over also.

Now make a lib\mingw\ nested subdirectory (for example C:\Libtcod\libtcod\dependencies\SDL-1.2.20\lib\mingw) and copy over libSDL.dll.a from the lib subdirectory of the 64-bit SDL (e.g. C:\SDL\SDL-1.2-20111107-win64\lib) into ...\SDL-1.2.20\lib\mingw.

Verifiy that the contents of the SDL-1.2.15 and SDL-1.2.20 directories now mirror each other. Remember that the .20 version will contain 64-bit versions of SDL.

6a. You will also have to replace the SDL.dll file in the root libtcod directory (e.g. C:\Libtcod\libtcod\SDL.dll) with the one from the 64-bit SDL distribution (found in \bin there, e.g. C:\SDL\SDL-1.2-20111107-win64\bin\SDL.dll).

7. Now go to back to the libtcod directory and go into the makefiles directory (in my case it is C:\Libtcod\libtcod\makefiles). Make copies of the makefile-mingw and makefile-samples-mingw files and name them makefile-mingw-64 and makefile-samples-mingw-64 respectively.

8. Editing makefile-mingw-64, you need to change the following lines:

#9: From "SDL_DIR=dependencies/SDL-1.2.15" to "SDLDIR=dependencies/SDL-1.2.20"
#22: From "CC=mingw32-gcc" to "CC=x86_64-w64-mingw32-gcc"
#23: From "CPP=mingw32-g++" to "CPP=x86_64-w64-mingw32-g++"

This is to ensure that the proper 64-bit version of mingw that we installed in Step 1. is used to compile.

9. Editing makefile-samples-mingw-64, you need to change the following lines:

#6: From "SDLDIR=dependencies/SDL-1.2.15"
#8: From "CC=mingw32-gcc" to "CC=x86_64-w64-mingw32-gcc"
#9: From "CPP=mingw32-g++" to "CPP=x86_64-w64-mingw32-g++"

10. Now you can compile libtcod, and the samples. To do this, replace the makefiles targeted in the make commands given in "Compiling libtcod" with the new 64-bit makefiles:

"make -f makefiles/makefile-mingw" becomes "make -f makefiles/makefile-mingw-64"


"make -f makefiles/makefile-samples-mingw" becomes "make -f makefiles/makefile-samples-mingw-64"

Note that the call to the UPX executable packer may fail at the end of the build process. Ignore this, its not that important (IMHO).

11. You can now run the 64-bit samples app to make sure it runs ok. Which it should.  :)

12. For informational purposes, here are my relevant Code::Blocks "Build Options" for compiling a 64-bit libtcod project successfully in C++11. Please remember to highlight the top-level build option on the left-hand side of the "Project Build Options" to apply these to both Debug and Release and any other build types you have defined":

Compiler Settings/Compiler Flags:

Checked: "Have G++ follow the C++11 ISO C++ Language Standard [-std=c++11]"

Compiler Settings/Other Options:

-isystem "C:/Libtcod/libtcod/include" (this is set to avoid generating warnings for Libtcod files when building)

Linker Settings/Link Libraries:

Add ..\..\..\Libtcod\libtcod\lib\libtcod-mingw.a (in my case this is C:\Libtcod\libtcod\lib\libtcod-mingw.a, i.e. it refers to the rebuilt libtcod library)

Search Directories/Compiler:

..\..\..\Libtcod\libtcod\include (in my case this is C:\Libtcod\libtcod\include)

Pre/post build steps/Post-build steps:

cmd /c copy "C:\Libtcod\libtcod\lib\libtcod-mingw.a" $(TARGET_OUTPUT_DIR)
cmd /c copy "C:\Libtcod\libtcod\libtcod-mingw.dll" $(TARGET_OUTPUT_DIR)
cmd /c copy "C:\Libtcod\libtcod\SDL.dll" $(TARGET_OUTPUT_DIR)

(note the quotes around the paths. Although not needed in this case, Code::blocks doesn't handle spaces in paths very well (see Step 1)).

And success!


  • Rogueliker
  • ***
  • Posts: 329
  • Karma: +0/-0
    • View Profile
    • Email
Thanks for posting this.  I'm also on Win7/64bit but the burden of getting it working myself, versus taking and using what Jice offers, is too much for me.  Still, these kinds of guides where someone has written up all the steps they took to get it working, are gold when someone else wants to do it later on.  Cheers!


  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Is all that crap because 64 bit version?

I remember my C::B adventure went like this:
-download C::B with mingw and install
-download SDL dev version, copy SDL folder to include of mingw and libraries to where they are
-start writing programs (with couple of SDL specific linker settings)


  • Rogueliker
  • ***
  • Posts: 99
  • Karma: +0/-0
    • View Profile
    • Email
Its also to use POSIX-threads (i.e. C++#1's std::thread) on Win7.


  • Rogueliker
  • ***
  • Posts: 447
  • Karma: +0/-0
  • $@ \in \{1,W\} \times \{1,H\}$
    • View Profile
    • Klein Roguelikes
If you want games to be portable to other people's computers, you should probably compile them as 32-bit rather than 64-bit. You can compile to both 32 and 64 for portability, but unless your game is very CPU-intensive there's no real benefit to having a 64-bit Windows version. 32-bit games run fine on Win7/64.


  • Rogueliker
  • ***
  • Posts: 99
  • Karma: +0/-0
    • View Profile
    • Email
Aye, will indeed do so (just a matter of passing  -m64 or -m32 to g++)