Difference between revisions of "Codeblocks setup"

From The Powder Toy
Jump to: navigation, search
(Added easy-to-use ready-to-compile-out-of-the-box source package for TPT, no downloading of CodeBlocks etc needed.)
(Updated project file, and other minor tweaks)
Line 7: Line 7:
 
Environmental variable instuctions by pilojo.
 
Environmental variable instuctions by pilojo.
  
Last modified: 01/27/2012
+
Last modified: 06/07/2012
  
  
Line 14: Line 14:
 
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.
  
By the way, if you wish to skip this HUGE tutorial and just do the compiling, I've posted a link here to download a FULL SOURCE + COMPILER package of the latest version (as of me writing this on 5/22/2012) of TPT. It includes a pre-installed copy of CodeBlocks and MinGW, the source code for TPT (version 79.2) and all needed libraries. It is VERY simple to use. Just unzip this ZIP file into any directory, go into the codeblocks folder, and run codeblocks.exe. If it's the first time you've run it, it'll ask you what compiler to use and also if you want to associate C and C++ source code files with CodeBlocks. At both of these dialog boxes just click "yes" or "ok" to accept the default settings. Then go to the File menu, and select Open, and navigate to the folder that has your TPT project, which in this package is called "FacialTurd-The-Powder-Toy-0fb6b85". Then double click the file called Powder.cbp (and in case your Windows Explorer is set to hide extensions of known file types, you'll be able to tell the correct file because it will show as Powder will have a red/green/blue/yellow grid of squares as the icon which is the CodeBlocks logo). Once this has loaded just press the F9 key on your keyboard (or go to the Build menu and select Build and Rune) and it will compile TPT and run it. Congrats, you have just compiled your own copy of TPT from the source code! As you see there were no complicated settings or environment variables to mess with, thus negating the need for the long tutorial that you will see below here on this webpage.
+
If you have neither MinGW nor Code::Blocks, and don't feel like going through all of this, then you can download [http://www.mediafire.com/?svpdgp8v2vw6oev this file] containing everything you need to compile TPT, including the Code::Blocks IDE, the MinGW compiler, and the source code for TPT v79.2.
The download link for the complete package referred to in this paragraph is: [http://www.mediafire.com/?svpdgp8v2vw6oev http://www.mediafire.com/?svpdgp8v2vw6oev]
+
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 below (it might still work if you don't, but that's not guaranteed).
 +
 
 +
If you already have Code::Blocks and/or MinGW and don't want to go through this tutorial, there's a download below (under "Preparing the project") containing just the source (including the necessary libraries) and a project file which you can use.
 +
 
 +
In any case, 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.
  
 
==  MinGW Preparation  ==
 
==  MinGW Preparation  ==
Line 21: Line 25:
 
* Add <code>"C:\MinGW\bin"</code> to the PATH environment variable, without quotes.
 
* Add <code>"C:\MinGW\bin"</code> to the PATH environment variable, without quotes.
  
(If you don't know what an environmental variable is, here is how to get to it.)
+
(If you don't know how to set environment variables, here is how to do it.)
 
* 1. Go to My Computer.
 
* 1. Go to My Computer.
 
* 2. System properties/settings.
 
* 2. System properties/settings.
Line 38: Line 42:
  
 
==  Preparing the project  ==
 
==  Preparing the project  ==
* Note: If you can't be bothered to do all of this yourself, [http://min.us/mDIQTFGOZ#1o here] is a zip file containing a project file and all necessary headers, libraries, and the source for v71.3 of The Powder Toy. For this to work, you must have MinGW GCC 4.6.1 or later installed (if you downloaded the MinGW from above, you should be fine). If you have an earlier version and/or that project file doesn't work for you, try [http://minus.com/mDIQTFGOZ#2 this one].
+
* Note: If you can't be bothered to do all of this yourself, [http://min.us/mDIQTFGOZ here] is a zip file containing a project file and all necessary headers, libraries, and the source for v80.3 of The Powder Toy. For this to work, you must have the latest version of MinGW installed (if you downloaded the MinGW from above, you should be fine). If the project file doesn't work for you, try updating your MinGW and/or going through the steps below.
* Download [https://github.com/FacialTurd/The-Powder-Toy/zipball/master the latest source] and put it in an empty folder.
+
* 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].
 
* Download [http://min.us/mXxa5O8P1 these libraries] and extract it directly into the source folder.
 
* Download [http://min.us/mXxa5O8P1 these libraries] and extract it directly into the source folder.
 
* Open Code::Blocks.
 
* Open Code::Blocks.
Line 52: Line 56:
 
* Under Compiler Flags, make sure that everything is unchecked.
 
* Under Compiler Flags, make sure that everything is unchecked.
 
* Under Other Options, type in (put it all in one line)
 
* 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
+
  -w -m32 -std=c99 -mincoming-stack-boundary=2 -D_POSIX_C_SOURCE=200112L -DLUACONSOLE -DGRAVFFT
-DPTW32_STATIC_LIB -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -march=native -mtune=native -DX86
+
-D_GNU_SOURCE -DWIN32 -DPTW32_STATIC_LIB -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations
-DX86_SSE2 -msse2
+
-march=native -mtune=native -DX86 -DX86_SSE2 -msse2
* If, after following all of these steps exactly, the project won't compile, try removing the -DGRAVFFT part of the above line or updating your MinGW installation.
 
  
 
* Go to the Search Directories tab at the top of the build options window.
 
* Go to the Search Directories tab at the top of the build options window.
Line 63: Line 66:
 
* Now go to the Linker Settings tab at the top of the build options window.
 
* 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)
 
* 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
+
  -s -static -lmingw32 -lregex -lpthreadGC2 -lws2_32 -lSDLmain -lSDL -luser32 -lgdi32 -lwinmm -lfftw3f
-llua5.1 -mwindows
+
-lm -lbz2 -llua5.1 -mwindows
* If you didn't add -DGRAVFFT to the compiler options, you can remove "-lfftw3f" from the above line.
 
 
* Hit OK at the very bottom.
 
* Hit OK at the very bottom.
  
 
==  Compiling  ==
 
==  Compiling  ==
* Press Ctrl+F9 in your keyboard.
+
* Press Ctrl+F9 in your keyboard to compile.
* It should compile. If not, 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 compilation fails, try updating your MinGW installation or 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.]]
 
* If it compiles continue to the [[Coding-tutorial|element coding tutorial.]]
  
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 23:48, 7 June 2012

Author: tian110796

Fixed by macweirdo for Version 47 (Python Console Fixes)

Some parts are from JojoBond.

Environmental variable instuctions by pilojo.

Last modified: 06/07/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.

If you have neither MinGW nor Code::Blocks, and don't feel like going through all of this, then you can download this file containing 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 below (it might still work if you don't, but that's not guaranteed).

If you already have Code::Blocks and/or MinGW and don't want to go through this tutorial, there's a download below (under "Preparing the project") containing just the source (including the necessary libraries) and a project file which you can use.

In any case, 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.

MinGW Preparation

  • Download and Install MinGW using the default settings (You can also install the C++ compiler if you feel like it, but it's not necessary).
  • Add "C:\MinGW\bin" to the PATH environment variable, without quotes.

(If you don't know how to set environment variables, here is how to do 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-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
  • 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

  • Note: If you can't be bothered to do all of this yourself, here is a zip file containing a project file and all necessary headers, libraries, and the source for v80.3 of The Powder Toy. For this to work, you must have the latest version of MinGW installed (if you downloaded the MinGW from above, you should be fine). If the project file doesn't work for you, try updating your MinGW and/or going through the steps below.
  • 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 compilation fails, try updating your MinGW installation or 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.