Using KDevelop with libnds and devkitARM

Tuesday, July 31st, 2007

KDevelop is a full featured IDE for the K Desktop Environment.
In order to take full advantage of the facilities KDevelop has to offer, we’re going to take an existing template based project, and import it as a Makefile project in KDevelop.

In order to do this, first create a template based project as described in the “Using the provided template Makefile” tutorial.

Now that you have your project directory set up it’s time to import the directory into KDevelop and make a KDevelop project file.

To do this, click the “Project” menu, and then the “Import Existing…” to bring up the import existing project dialog. Select the project directory you made in the first part of this tutorial and give the project a name.

For project type you’re going to want to select either “Generic C Project (Custom Makefiles)” or “Generic C++ Project (Custom Makefiles)” your choice of C or C++ doesn’t matter too much at this juncture, so just stick with C. We select “Custom Makefiles” because we want to use the provided nds-example template makefile.

Finally enter your name and e-mail address and click next.
When it asks you if you want to populate the project with files from the source, go ahead and click yes.

You now have a project file for your project directory!
Unfortunately you’re not done yet. If you attempted to compile your project now you’d notice that you wouldn’t get very far. KDevelop will start with a clean environment for the project, so we need to set DEVKITARM and DEVKITPRO in our project.

To do this click “Project” then “Project Options” then select “Build Options” and finally the “Make” tab. There will be a section for environment variables. Add the appropriate variables for DEVKITARM and DEVKITPRO and click “Ok”. At this point your project should now successfully compile!

You could start developing right now, but you’d quickly notice that code completion doesn’t work for types and functions. This is because KDevelop needs to be told where the devkitARM and libnds include files reside.

To set this select “Project” then “Project Options” and choose “C++ Support”. At the bottom of the dialog there is a section for custom “Code Completion Databases” this is really just a collection of paths to the include files you’ll be using to develop your application.

Create one of type “KDevelop Custom Directory PCS Importer” and provide the paths to the devkitARM and libnds include directories. If you followed the environment instructions exactly these should be:

/usr/local/devkitPRO/devkitARM/include
/usr/local/devkitPRO/libnds/include

Click next and name the PCS importer something witty and original like… oh… “NDS Homebrew Includes”.

Click ok and you should now have working code completion!
A word of warning, there is a known issue with the current stable KDevelop (3.2 tree) which causes typedefs for structs of the form below not to work.

typedef struct {
	struct members
} typeName;

Any structs declared as such will not complete correctly. In addition, KDevelop will not code complete #define variables such as the VRAM_A_* types. I have yet to find a way to fix this.

So you can compile and code complete. But I’ll bet my dinner that you want to be able to actually EXECUTE our compiled source so that the “Run” command does what you would expect right? Well, if you’ve installed an emulator you can tell KDevelop to use that emulator to execute your nds file.

To set the emulator as your executable click “Project” and “Project Options” then select “Run Options” enter the full path to your emulator on the executable line, and in the arguments line give the full path to your project NDS file. In most cases this will just be the name of your project directory with .nds at the end. For our helloworld project the resulting file will be “helloworld.nds”.

You now have a full featured KDevelop project!
One word of warning: If you did set an executable in the Run Options, then every time you open up the project options KDevelop will screw this section up. You’ll need to edit the file to remove the “file://” that KDevelop inserts at the beginning.

Using Notepad++ with devkitARM and libnds

Tuesday, July 31st, 2007

First follow the instructions for creating a template based project.

Once you have that set up you’re almost finished.
All you need to do is set up the relevant application binds so you can build your project from within Notepad++.

Unfortunately Notepad++ is not an IDE, as such it was not designed to compile applications.
In order to do this we need a few helper scripts that Notepad++ can call to build and clean our project.

I’ve taken the liberty of creating a “build script” to help in this process.

Download the Notepad++ Project Build Helper Script file here and extract its contents to “c:\Program Files\Notepad++\”.
Note: Extracting this archive will remove any existing NppExec scripts you already have defined! Merge the configuration files together if you wish to maintain your existing scripts.

Extracting the archive will set up two NppExec scripts called “Build Project” and “Clean Project”. These two scripts will build and clean the project respectively. In addition it will bind the NppExec run dialog to F8.

Now to compile your project just open a file in your projects source directory, hit F8, select “Build Project”, and click “Ok”

When you run the build script a command console will open in Notepad++ which will display the result of the build.
If there are any errors in the build the errors will be displayed in the console. Individual errors can be double clicked to jump to the line on which the error occurred.

You now have everything you need to develop in Notepad++.

Using devkitARM and libnds with Visual Studio 2005

Monday, July 30th, 2007

I’m primarily a Linux user, as such I do almost all of my development in Linux either using gVim or KDevelop. Despite my affinity for the aforementioned IDEs and OS I would still be hard pressed to find an IDE better than Microsoft Visual Studio 2005.

This being said, using Visual Studio 2005 with devkitARM and libnds is both simple and a joy. The setup procedure can seem a little daunting (especially if you’ve never had to configure your own Visual Studio project before) but it’s not too bad.

Note: The NDS Example files do come with a Visual C++ project which can be imported, and can be used as a good building block to start a full solution from, however, if we did that we wouldn’t learn anything. ;)

First follow the instructions for creating a template based project.

In order to create a solution you’re going to have to open Visual Studio and import our existing template as a project. Luckily for us Microsoft Visual Studio 2005 has a nifty wizard which will help us with just that.

Click the “File” menu, select “New”, and click “Project from Existing Code…”.
You will be presented with the dialog shown below. You’re going to want to select Visual C++ project as the type and click next.

Visual Studio 2005 Setup - Step 1

The next screen allows us to select our project name and directory. Choose the project template directory mentioned earlier as the project directory, ensure that “Add files to the project from these folders” is checked. The project wizard will automatically add the project directory to the list of directories to populate the project with.

Visual Studio 2005 Setup - Step 2

Next we get to chose our build system. Make sure to chose external make system and select next.

Visual Studio 2005 Setup - Step 3
This screen is where the build magic happens. Lucky for us the amazing people over at devkitPro.org have already devised a simple make/sed combo which will allow the make output to be interpreted by visual studio as error reports it can understand.

The string is: make -r 2>&1 | sed -e ’s/(.[a-zA-Z]+):([0-9]+):/1(2):/’

This string should be used as both the build command line, as well as the rebuild command line.
Use “make clean” for the clean command line.

Finally use the name of the project directory with .nds at the end as the Debugging output.

Visual Studio 2005 Setup - Step 4

Click next, select same as Debug settings, and click finish!
You should now have a working project solution!

You can now build your project and watch as Visual Studio chugs along and builds with our magic build command line. This is fine and dandy, but after a little development you’ll notice that IntelliSense (Microsoft’s proprietary code-completion) doesn’t completely work. In addition you have no way to effectively debug the Nintendo DS applications that have been built.

With a little bit of project configuration you can make IntelliSense work and cause debugging to launch your application in your emulator of choice.

Configuring IntelliSense

To configure IntelliSense you’ll need to add your devkitARM and libnds directories to both the project include directory list.

To get to the list, right click the project icon ( it will be located under the solution in the “Solution Explorer” sidebar ) and select “Properties”.

Once inside of the properties window make sure to select “All Configurations” from the configurations drop-down. Not doing so will cause the changes only to be applied to the Debug release, and changing the setting to Release will produce unexpected results.

Visual Studio 2005 Setup - Step 5

Executing your emulator of choice on application debugging

Select the “NMake” category under “Configuration Properties” and select “Include Search Path”.
Clicking “Include Search Path” should make a “…” button visible. Click the “…” to open the Include Search Path edit dialog. Add your Devkit Pro directories to the search path and click ok.

Finally, to set up your emulator to launch on project debug select the “Debugging Category” under “Configuration Properties”.

In this section you should be able to select your emulator command, arguments, and working directory.
Set “Command” to the emulator executable, set the “Command Arguments” to “$(TargetPath)” and set the “Working Directory” to the full path to the executable.

Visual Studio 2005 Setup - Step 5

Click ok and you should now have a fully functional Solution complete with IntelliSense and debug to emulator!