Codeblocks setup

From The Powder Toy
Revision as of 21:51, 28 October 2011 by gamax92 (talk | contribs) (Fixed links.)
Jump to: navigation, search

Author: tian110796

Fixed by macweirdo for Version 47 (Python Console Fixes)

Some parts are from JojoBond.

Environmental variable instuctions by pilojo.

Last modified: 10/28/2011


This is a guide for compiling using Code::Blocks with MinGW. This guide is targeted to those who are intimidated by the large Visual C++ Express download and is using Windows.

Note: This tutorial works only in Windows, but will work in Macintosh with minor changes.

MinGW Preparation

  • Download and Install MinGW using the default settings (Or install C++ compiler also, just to be sure).
  • Add "C:\MinGW\bin" to the PATH environment variable, without quotes.
  • Download the following libraries: LuaForWindows, SDL, bzip2, regex, and pthreads-win32.
  • Extract the libraries contents C:\MinGW\ so it overlaps the bin, lib, and include folders. Don't do this with LuaForWindows, leave it to the default place.

(If you don't know what an environmental variable is, here is how to get to it.)

  • 1. Go to My Computer.
  • 2. System properties/settings.
  • 3. Advanced system settings.
  • 4. Environmental Variables.
  • 5. Second box, scroll down till you see PATH.
  • 6. Click PATH, then click Edit.
  • 7. If there is not a semi-colin at the end of the line, add one and then add "C:\MinGW\bin" without quotes.
  • 8. Press OK
  • 9. Continue tutorial.

Code::Blocks preparation

  • Download and Install Code::Blocks here
  • In the first run, you will be asked what compiler to use. Select "MinGW" or "GNU GCC Compiler".
  • Code::Blocks is now ready!

Preparing the project

  • Download this and put it in an empty folder.
  • Open Code::Blocks
  • Create a new empty project.
  • Create project in the folder where your source exists. (sometimes it adds to the directory the Project name, if that happens, remove the Project name part from the directory)
  • In the Management window you will see the project name listed there. Right-click then add files recursively.
  • Click the Select All button
  • Now, the tricky part. Go to Project -> Build options -> Linker settings. Add the following in the link libraries:
C:\MinGW\lib\libmingw32.a
C:\MinGW\lib\libSDLmain.a
C:\MinGW\lib\libSDL.dll.a
C:\MinGW\lib\bzip2.lib
C:\MinGW\lib\libwsock32.a
C:\MinGW\lib\libws2_32.a
C:\MinGW\lib\libregex.dll.a
C:\Program Files\Lua\5.1\lib\lua5.1.lib
C:\MinGW\lib\libpthread.dll.a
  • Next, paste this into Other Linker Options, to the right of link libraries:

-static-libgcc -static-libstdc++

  • Now go to Search directories -> Compiler, still in Build Options. Add the following:
includes* (note: if you get air.h not found, try adding the full path to the includes folder)
C:\MinGW\include\SDL
C:\MinGW\include\
  • The last one. In Compiler Settings -> Other options, still in Build Options, Add the line:
-w -m32 -std=c99 -D_POSIX_C_SOURCE=200112L -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -mmmx -DX86 -mwindows -DWIN32

Compiling

  • Press F9 in your keyboard.
  • It should compile. If not, post in the HELP secton on the forums with a pastebin of your compiling error
  • If it compiles continue to the element coding tutorial.