Difference between revisions of "Codeblocks setup"

From The Powder Toy
Jump to: navigation, search
m (1 revision)
m (Reverted edits by HerpesMaster11 (talk) to last revision by jacob1)
 
(27 intermediate revisions by 11 users not shown)
Line 1: Line 1:
<h1> Setting up Code::Blocks  </h2>
+
  This Guide is Old and will no longer work
 +
 
 +
 
 +
 
 
Author: tian110796
 
Author: tian110796
  
Line 8: Line 11:
 
Environmental variable instuctions by pilojo.
 
Environmental variable instuctions by pilojo.
  
Last modified: 5/21/2011
+
Last modified: 10/09/2012
  
  
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.
+
This is a guide for compiling using Code::Blocks with MinGW. This guide is targeted to Windows users who are intimidated by the large Visual C++ Express download.
  
Note: This tutorial works only in windows, but will work in Macintosh with minor changes.
+
Note: This tutorial works only in Windows, but will work in Macintosh with minor changes.
  
<h2>  MinGW Preparation  </h3>
+
==  Pre-made Project Files  ==
* Download [http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/| here] and install MinGW using the default settings (Or install C++ compiler also, just to be sure).
+
These downloads are intended for those who can't be bothered to do all of this him/herself. They are not guaranteed to be up-to-date, nor is there any guarantee that any of these will even work.
* Add C:\MinGW\bin; to the PATH environment variable
+
Hence, it is encouraged to try to do this all yourself (it may look long, but it's really not that bad) rather than relying on these downloads, which may or may not be kept up-to-date.
* Download SDL [[http:''www.libsdl.org/release/SDL-devel-1.2.14-mingw32.tar.gz| here]] and bzip2 [[http:''gnuwin32.sourceforge.net/downlinks/bzip2-bin-zip.php| here]] and regex [http://gnuwin32.sourceforge.net/downlinks/regex-bin-zip.php| here]
 
* Extract the folders in these files to C:\MinGW\ so that it coincides to the bin, lib, and include folders of the MinGW installation.
 
  
(If you don't know what an environmental variable is, here is how to get to it.)
+
'''If you have neither MinGW nor Code::Blocks installed:'''
 +
[http://www.mediafire.com/?svpdgp8v2vw6oev This download] contains everything you need to compile TPT, including the Code::Blocks IDE, the MinGW compiler, and the source code for TPT v79.2.
 +
If you download this, it's still a good idea to add the bin directory containing the MinGW executables to the PATH environment variable as described at the bottom of the "MinGW Preparation" section below (it might still work if you don't, but that's not guaranteed).
 +
 
 +
'''If you already have Code::Blocks and/or MinGW installed:'''
 +
[https://www.dropbox.com/s/m5eaogaalsigjrx/TPT%20CodeBlocks%20project.zip This download] contains a project file and all necessary headers, libraries, and the source for v83.0 of The Powder Toy. '''For this to work, you must have the correct version of MinGW (4.6.x) installed. Otherwise, you may get errors about undefined references to '__chkstk_ms'. In particular, the default Code::Blocks + MinGW installation will ''not'' work with this project file.''' If this project file doesn't work for you, try updating your MinGW and/or going through the steps below. Sorry for any inconveniences this may cause you.
 +
 
 +
==  MinGW Preparation  ==
 +
* There are multiple ways (not just the ones listed below) to install the correct version of MinGW. Regardless of how you install MinGW, note that '''you must have MinGW 4.6.x in order to build successfully. If you install an older version, you may get errors about undefined references to '__chkstk_ms', and if you install a newer version, the compiled executable will most likely crash.'''
 +
* Here are two ways to install MinGW:
 +
'''First method (untested)'''
 +
* Download [http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/Previous/1.1006.0/tdm-gcc-4.6.1.exe/download TDM-GCC]. (this isn't ''exactly'' MinGW per se, but it's close enough and should work)
 +
* Uncheck "Check for updated files on the TDM-GCC server", and press "Create".
 +
* Change the installation directory to C:\MinGW. (You could probably leave it as it is if you want, but from here on out, this tutorial will assume C:\MinGW as the directory in which MinGW is installed.)
 +
* Leave all of the checkboxes as is, unless you don't want to install the C++ compiler (g++, under "gcc") or the debugger (GDB). Definitely leave "Add to PATH" checked, though. Then click "Install".
 +
 
 +
'''Second method (for the more technologically advanced)'''
 +
* Download [http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.5-beta-20120426-1/mingw-get-0.5-mingw32-beta-20120426-1-bin.zip/download mingw-get], which is MinGW's official command-line installer.
 +
* Extract the contents to C:\MinGW.
 +
* Add <code>"C:\MinGW\bin"</code> to the PATH environment variable, without quotes (see below if you don't know how).
 +
* Open up a command prompt window, and type <code>mingw-get install mingw-get</code>, followed by <code>mingw-get update</code>.
 +
* To install MinGW GCC 4.6.2, type <code>mingw-get install "gcc<4.7" "g++<4.7" mingw32-make gdb</code> (the quotes are necessary so that the shell doesn't interpret it as input redirection). If you don't want to install the C++ compiler, the GNU 'make' utility, or the GDB debugger, you can leave those out of the command if you wish.
 +
 
 +
'''How to add MinGW to the PATH environment variable:'''
 
* 1. Go to My Computer.
 
* 1. Go to My Computer.
 
* 2. System properties/settings.
 
* 2. System properties/settings.
Line 28: Line 52:
 
* 5. Second box, scroll down till you see PATH.
 
* 5. Second box, scroll down till you see PATH.
 
* 6. Click PATH, then click Edit.
 
* 6. Click PATH, then click Edit.
* 7. If there is no " ; " at the end of the line, add one and then add C:\MinGW\bin; .
+
* 7. If there is not a semi-colon at the end of the line, add one and then add <code>"C:\MinGW\bin"</code> without quotes.
* 8. Hit ok
+
* 8. Press OK
 
* 9. Continue tutorial.
 
* 9. Continue tutorial.
  
<h2>  Code::Blocks preparation </h3>
+
==  Code::Blocks preparation   ==
* Download Code::Blocks [http://prdownload.berlios.de/codeblocks/codeblocks-10.05-setup.exe| here]
+
* Download and Install Code::Blocks [http://prdownload.berlios.de/codeblocks/codeblocks-10.05-setup.exe here]. '''Do not install the MinGW compiler that is shipped with it, or you may get errors about undefined references to '__chkstk_ms'. Instead, use one of the above methods to install MinGW.'''
* Install Code::Blocks
 
 
* In the first run, you will be asked what compiler to use. Select "MinGW" or "GNU GCC Compiler".
 
* In the first run, you will be asked what compiler to use. Select "MinGW" or "GNU GCC Compiler".
 
* Code::Blocks is now ready!
 
* Code::Blocks is now ready!
  
<h2>  Python Preparation  </h3>
+
==  Preparing the project  ==
* Go [http://www.python.org/download/releases/2.7.1/| here] and click on the Windows x86 MSI Installer (2.7.1) link, '''NOT''' the x64 version.
+
* Download [https://github.com/FacialTurd/The-Powder-Toy/zipball/master the latest source] and put it in an empty folder. Or, if you want to compile the latest stable version, look [https://powdertoy.co.uk/Download/Browse.html here].
* [http://github.com/FacialTurd/The-Powder-Toy| Download this (using the large download button] and put it in an empty folder.
+
* Download [https://www.dropbox.com/s/41mq5ryuk3lra3q/TPT%20MinGW%20static%20libs.zip these libraries] and extract it directly into the source folder.
* Run the script in it called getheader.py, wait for it to finish.
+
* Open Code::Blocks.
<h2>  Preparing the project  </h3>
+
* Create a new empty project in the folder where your source exists. (sometimes it adds the project name to the directory; if that happens, remove the project name part from the directory)
* Create a new empty project.
+
* In the Management window you will see the project name listed there. Right-click it, click "Add files recursively...", and choose the folder where all of the files are.
* 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)
+
* Leave all the checkboxes as they are and click "OK".
* In the Management window you will see the project name listed there. Right-click then add files recursively.
+
* At the very top of the window, next to "Build target:", open the drop-down menu and click "Release". (it probably won't matter because of the next few steps, but it's still a good thing to do)
* 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:\Python27\libs\python27.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:
+
* Go to Project -> Properties -> Build targets, and for every build target on the left, find the drop-down menu on the right next to "Type:" and change it from "Console Application" to "GUI Application". (You don't have to, but it's a good idea to do so.)
  
includes* (note: if you get air.h not found, try adding the full path to the includes folder)
+
* Go to Project -> Build options -> Compiler Settings.
 +
* Under Compiler Flags, make sure that everything is unchecked.
 +
* Under Other Options, type in (put it all in one line)
 +
-w -m32 -std=c99 -mincoming-stack-boundary=2 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -DGRAVFFT
 +
-D_GNU_SOURCE -DWIN32 -DPTW32_STATIC_LIB -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations
 +
-march=native -mtune=native -DX86 -DX86_SSE2 -msse2
  
C:\MinGW\include\SDL
+
* Go to the Search Directories tab at the top of the build options window.
 +
* Under the Compiler tab, click Add, and browse to and add the "includes" folder of the source to the list. (It should be okay to leave it as a relative path, but if you get a bunch of errors about various .h files not being found, try using the full path of the includes folder.)
 +
* Under the Linker tab, click Add, and add the "lib" folder of the source to the list. (as with the includes folder, you may or may not have to use the full path of the lib folder.)
  
C:\MinGW\include\
+
* Now go to the Linker Settings tab at the top of the build options window.
 +
* Under "Other Linker Options", type in (again, have it all in one line)
 +
-s -static -lmingw32 -lregex -lpthreadGC2 -lws2_32 -lSDLmain -lSDL -luser32 -lgdi32 -lwinmm -lfftw3f
 +
-lm -lbz2 -llua5.1 -mwindows
 +
* Hit OK at the very bottom.
  
* The last one. In Compiler Settings -> Other options, still in Build Options, Add the line:
+
==  Compiling  ==
-w -m32 -std=c99 -D_POSIX_C_SOURCE=200112L -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -mmmx -DX86 -mwindows -DWIN32
+
* Press Ctrl+F9 in your keyboard to compile.
 +
* If you get errors about undefined references to '__chkstk_ms', your version of MinGW is too old. Try installing MinGW as described in the "MinGW Preparation" section above.
 +
* If compilation fails in any other way, try removing -DGRAVFFT from the compiler options and -lfftw3f from the linker options.
 +
* If you still can't get it to compile, post in [https://powdertoy.co.uk/Discussions/Categories/Topics.html?Category=5 the forums] with a [http://pastebin.com/ pastebin] of your error(s).
 +
* If it compiles continue to the [[Coding-tutorial|element coding tutorial.]]
  
<h2>  Compiling </h3>
+
[[Category:Development]]
* Press F9 in your keyboard.
+
[[Category:Compiling]]
* It should compile. If not, Converse with tian110796, macweirdo, or cracker64
 
* If it compiles continue to the element coding tutorial.
 

Latest revision as of 04:53, 26 December 2022

This Guide is Old and will no longer work


Author: tian110796

Fixed by macweirdo for Version 47 (Python Console Fixes)

Some parts are from JojoBond.

Environmental variable instuctions by pilojo.

Last modified: 10/09/2012


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

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

Pre-made Project Files

These downloads are intended for those who can't be bothered to do all of this him/herself. They are not guaranteed to be up-to-date, nor is there any guarantee that any of these will even work. Hence, it is encouraged to try to do this all yourself (it may look long, but it's really not that bad) rather than relying on these downloads, which may or may not be kept up-to-date.

If you have neither MinGW nor Code::Blocks installed: This download contains everything you need to compile TPT, including the Code::Blocks IDE, the MinGW compiler, and the source code for TPT v79.2. If you download this, it's still a good idea to add the bin directory containing the MinGW executables to the PATH environment variable as described at the bottom of the "MinGW Preparation" section below (it might still work if you don't, but that's not guaranteed).

If you already have Code::Blocks and/or MinGW installed: This download contains a project file and all necessary headers, libraries, and the source for v83.0 of The Powder Toy. For this to work, you must have the correct version of MinGW (4.6.x) installed. Otherwise, you may get errors about undefined references to '__chkstk_ms'. In particular, the default Code::Blocks + MinGW installation will not work with this project file. If this project file doesn't work for you, try updating your MinGW and/or going through the steps below. Sorry for any inconveniences this may cause you.

MinGW Preparation

  • There are multiple ways (not just the ones listed below) to install the correct version of MinGW. Regardless of how you install MinGW, note that you must have MinGW 4.6.x in order to build successfully. If you install an older version, you may get errors about undefined references to '__chkstk_ms', and if you install a newer version, the compiled executable will most likely crash.
  • Here are two ways to install MinGW:

First method (untested)

  • Download TDM-GCC. (this isn't exactly MinGW per se, but it's close enough and should work)
  • Uncheck "Check for updated files on the TDM-GCC server", and press "Create".
  • Change the installation directory to C:\MinGW. (You could probably leave it as it is if you want, but from here on out, this tutorial will assume C:\MinGW as the directory in which MinGW is installed.)
  • Leave all of the checkboxes as is, unless you don't want to install the C++ compiler (g++, under "gcc") or the debugger (GDB). Definitely leave "Add to PATH" checked, though. Then click "Install".

Second method (for the more technologically advanced)

  • Download mingw-get, which is MinGW's official command-line installer.
  • Extract the contents to C:\MinGW.
  • Add "C:\MinGW\bin" to the PATH environment variable, without quotes (see below if you don't know how).
  • Open up a command prompt window, and type mingw-get install mingw-get, followed by mingw-get update.
  • To install MinGW GCC 4.6.2, type mingw-get install "gcc<4.7" "g++<4.7" mingw32-make gdb (the quotes are necessary so that the shell doesn't interpret it as input redirection). If you don't want to install the C++ compiler, the GNU 'make' utility, or the GDB debugger, you can leave those out of the command if you wish.

How to add MinGW to the PATH environment variable:

  • 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-colon 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. Do not install the MinGW compiler that is shipped with it, or you may get errors about undefined references to '__chkstk_ms'. Instead, use one of the above methods to install MinGW.
  • 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 the latest source and put it in an empty folder. Or, if you want to compile the latest stable version, look here.
  • Download these libraries and extract it directly into the source folder.
  • Open Code::Blocks.
  • Create a new empty project in the folder where your source exists. (sometimes it adds the project name to the directory; 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 it, click "Add files recursively...", and choose the folder where all of the files are.
  • Leave all the checkboxes as they are and click "OK".
  • At the very top of the window, next to "Build target:", open the drop-down menu and click "Release". (it probably won't matter because of the next few steps, but it's still a good thing to do)
  • Go to Project -> Properties -> Build targets, and for every build target on the left, find the drop-down menu on the right next to "Type:" and change it from "Console Application" to "GUI Application". (You don't have to, but it's a good idea to do so.)
  • Go to Project -> Build options -> Compiler Settings.
  • Under Compiler Flags, make sure that everything is unchecked.
  • Under Other Options, type in (put it all in one line)
-w -m32 -std=c99 -mincoming-stack-boundary=2 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -DGRAVFFT
-D_GNU_SOURCE -DWIN32 -DPTW32_STATIC_LIB -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations
-march=native -mtune=native -DX86 -DX86_SSE2 -msse2
  • Go to the Search Directories tab at the top of the build options window.
  • Under the Compiler tab, click Add, and browse to and add the "includes" folder of the source to the list. (It should be okay to leave it as a relative path, but if you get a bunch of errors about various .h files not being found, try using the full path of the includes folder.)
  • Under the Linker tab, click Add, and add the "lib" folder of the source to the list. (as with the includes folder, you may or may not have to use the full path of the lib folder.)
  • Now go to the Linker Settings tab at the top of the build options window.
  • Under "Other Linker Options", type in (again, have it all in one line)
-s -static -lmingw32 -lregex -lpthreadGC2 -lws2_32 -lSDLmain -lSDL -luser32 -lgdi32 -lwinmm -lfftw3f
-lm -lbz2 -llua5.1 -mwindows
  • Hit OK at the very bottom.

Compiling

  • Press Ctrl+F9 in your keyboard to compile.
  • If you get errors about undefined references to '__chkstk_ms', your version of MinGW is too old. Try installing MinGW as described in the "MinGW Preparation" section above.
  • If compilation fails in any other way, try removing -DGRAVFFT from the compiler options and -lfftw3f from the linker options.
  • If you still can't get it to compile, post in the forums with a pastebin of your error(s).
  • If it compiles continue to the element coding tutorial.