Home‎ > ‎Tutorials‎ > ‎SGDK‎ > ‎

Tutorial 1 : Setup SGDK

While writing this tutorial, I used SGDK 1.01 and Code::Blocks 13.12.

Purpose

This tutorial will help you get the SGDK compiler setup in a Code::Blocks environment.

Download Required Files

You will need to download the required SGDK and CodeBlocks files. As of the writing of this tutorial, SGDK 1.11 and Code::Blocks 13.12 were the latest verions. Note that I used SGDK 1.01 in this tutorial...

SGDK

Download the latest SGDK here. You will need to extract the archive to your drive - I recommend "C:\Dev\SGDK" but this is an arbitrary choice; place it wherever you like.

Code::Blocks

Download the latest Code::Blocks here. Follow the installer instructions, if you can't do this then stop immediately and forget about dev'ing altogether.

Setup Environment Variables

You'll need to setup two new environment variables under Windows in order to compile using SGDK: GDK and GDK_WIN.
  • Press "Windows-Key + Pause" - this will bring up the System menu
  • Select "Advanced System Properties" from the left menu

  • Click on "Environment Variables" at the bottom right
  • Click on "New" under "User Variables for ..." (top half) and enter:
    • Variable Name: GDK
    • Variable Value: C:/Dev/SGDK - replace with your install directory if different
  • Enter a second user variable
    • Variable Name: GDK_WIN
    • Variable Value: C:\Dev\SGDK - replace with your install directory if different
Before (left) and after (right), make sure you entered the correct back-slash and forward-slash for these entries.


You also need to add SGDK's /bin directory to your System Path variable.
  • In the bottom half of the screen under "System Variable" scroll down to the variable named "Path" and click on "Edit..."
  • Scroll to the end of the string and add ";%GDK_WIN%\bin"
  • Press "OK"

Test by Building SGDK Library

Before moving on, we need to build the SGDK lib using the new environment variables. Every time you download a new version of SGDK you will need to rebuild the library. Also, since all of the library source files are included in %GDK_WIN%\src you can make modifications to the library code and re-build according to your needs.
  • Open a command line and type
 
 %GDK_WIN%\bin\make -f %GDK_WIN%\makelib.gen

You should see a whole bunch of stuff in the command line during library build, it'll take a few seconds to complete. If you were not successful, review the above steps and ensure your environment variables are setup properly.
  • Verify library build output is present by getting a directory listing of %GDK_WIN%\lib
  • Ensure that the creation date of your "libmd.a" file matches the present date (February 12th 2015 in my case)

At this point you could theoretically start writing 'C' programs and compiling them using the command line. You can do this by running this command directly from your project directory:

        %GDK_WIN%\bin\make -f %GDK_WIN%\makefile.gen


This should output a rom.bin file in the \out directory of your project.

Setup Code::Blocks

Writing code in a real IDE is much better than writing your programs in Notepad++ (unless that's what floats your boat). You should have Code::Blocks 13.12 installed before proceeding.

New Compiler Configuration

We'll need to configure SGDK as a new compiler in Code::Blocks.
  • Open Code::Blocks and go to Settings -> Compiler...
  • From the Dropdown list at the top, select the "GNU GCC Compiler" and click on "Copy"
  • Enter "SGDK" as the new compiler's name
  • Press "OK"

Next we need to point to all of SGDK's toolchain.
  • Click on the "Toolchain executables" tab
  • In "Compiler's installation directory", browse to the folder where you extracted SGDK - C:\Dev\SGDK in this tutorial
    • Unfortunately Code::Blocks does not recognize the environment variables we created earlier :(
  • Ensure all of the items under the "Program Files" tab match the values below. SGDK does not have a debugger so the default GDB/CDB can remain

That's it, Code::Blocks is configured to compile using SGDK!