Using devkitARM and libnds with Visual Studio 2005

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!

  • Reddit
  • del.icio.us
  • Technorati
  • Digg
  • StumbleUpon

21 Responses to “Using devkitARM and libnds with Visual Studio 2005”

  1. Alex Says:

    That was beautiful. All the other tutorials I’ve found on this subject have been woefully lacking in necessary details. Thanks!

  2. coderjoe Says:

    Hi Alex,

    I’m glad I was able to help. I figured a visual guide for Visual Studio 2005 might help someone. I’m glad I was right.

    Happy Hacking.

  3. Ed Says:

    Thank you very much for the tutorial. It was very easy to follow…even for a dummy like me!

  4. coderjoe Says:

    Hi Ed,

    Thanks for reading!
    I’m glad I could help. Hacking around on the DS was definitely some of the most fun I had programming this past summer.

    Here’s hoping I’ll get more time soon.

  5. Ed Says:

    Hey, can I ask you a question? I’m trying to get a just a plain text clock to appear on the screen, but the IPC->time.rtc member variables are all 0. Do you know how to work with the IPC? Is there some start-up code I need to call in order to use it? Say I just want to print the seconds passing. It should look something like this, right?

    iprintf(“seconds: %i”, IPC->time.rtc.seconds);

    Thank you very much in advance
    -ed

  6. coderjoe Says:

    @ed

    I remember running into the same issue at one point. I believe I forgot to set the IPC FIFO control register.

    I’ve looked through my code and found that when using IPC->time I would always initialize the rtc as follows at the top of my code:

    REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR;
    rtcReset();

    I would do this even before I initIrq().

    If you aren’t doing this it might make sense that IPC isn’t working, as the FIFO would not be enabled.

    Cheers.

  7. Ed Says:

    darn, that isn’t helping. Did you build off one of the templates? I think using the IPC has something to do with the ARM 7, but I can’t get any of it to work. Not even the “Real Time Clock” example that’s included with devkitPro works for me (on the DS, nor Dualis).

    Thank you so much again for your help. I don’t want to give up on DS homebrew! My larger scale PC game is getting a little too complex for how busy I actually am!

    -Ed

  8. Maik Says:

    Hello,
    first of all thanks a lot for the great tutorial.

    However, I am a bit confused about the configuration of the debugger. I did exactly as you explained, set some breakpoints in my main function, but after hitting run, it simply ignores my breakpoints.

    What am I doing wrong? Is debugging the .nds through the emulator actually possible?

    Regards
    Maik

  9. coderjoe Says:

    @Maik

    Glad you enjoyed the tutorial. As it stands you can not debug homebrew nintendo DS games through Visual Studio. I could be wrong, but I believe it to be true.

    When I initially presented the instructions for the tutorial my objective was to get the code to compile and execute in both modes (both release and debug). Without the changes doing a build all and run would do nothing.

    Debugger support is not included and breakpoints set in Visual Studio will not effect your ROM.

    If you learn of any way to get debugging support and breakpoints in Visual Studio please let me know.

    Cheers.

  10. Maik Says:

    @coderjoe,
    thank you for the quick reply and clearing that up. Then I will have to live without debugging.

    Did you, or anybody else tried to build the dualis emulator from source within Visual Studio with debugging information. Could that work?

    Unfortunately, dualis crashes on my computer, so I didn’t gave that a shot. I assume it’s just some missing DLLs from D3D8 or other libs, but I’m not sure.

    For now, I’ll just work with the free version of no$gba

    Regards
    Maik

  11. ariel Says:

    Great Article. Quick question what would be a better method using just libnds as described in your article or using PAlib as described in the vs2005 setup of this article:

    http://palib.info/wiki/doku.php?id=day1

    Thanks,
    Ariel

  12. coderjoe Says:

    @ariel,

    Glad you enjoyed the article.
    I’ve never used PAlib, but I’ve heard good things about it.

    It’s all about perspective. If you’d like to use PAlib please feel free, don’t let me stop you. I’ve heard it abstracts certain difficult concepts out that you would otherwise have to deal with when using libnds.

    Personally I started with libnds because I was curious. I like the fact that I’m “closer to the metal” with it.

    If you’re objective is to get a decent game/project going on the NDS I’d actually suggest you give PAlib a try.

    Then again I’ve never used it before, so don’t just take my word for it.

    I’d be interested in hearing your opinions if you do give it a try.

    Cheers!

  13. Martin Says:

    Hi

    Great article. Now I have some experience in C# but not that much in C++, and afaik .NET’s C++, VB and C# implementations all precompile down to the same intermediate language, so they are interchangable (in theory?). Is there any way to convert the default application to Visual Studio C# Express?

    Any light on the subject would be great!
    Thanks,

    Martin

  14. coderjoe Says:

    @Martin

    While I have very little experience with C# my gut instinct is that what you want to do would either be impossible, or very hard to do.

    As far as I can remember, C# is targeted at the CLI. I believe a lot of the functionality requires the .NET runtime as well.

    While you may be able to pre-compile all those languages down to the same intermediate language, that description right there puts you out of luck. When you program for an embedded platform such as the Nintendo DS you need to compile your applications down to architecture specific machine code.

    There’s no .NET runtime and no Common Language Infrastructure included on the Nintendo DS, so unless you can include that in a machine code compiled version of your application I doubt you’ll have any luck.

    Also please keep in mind that while my examples do present a C++ project, ndslib is a C library.

  15. KazenoZ Says:

    Thank you very very much!
    I’ve been looking for a few days now, but not single one of the, about, 300 other tutorials I found online explained how to make this work, each had their own workarounds and ways of implenting these in VS but none seemed to work, mostly because they weren’t detailed enough…

    This really helped me out configuring VS and I can now finally start programming for the DS too!
    Thank you very much, good sir!

  16. Holland Says:

    Excellent tutorial. Works great in VS2008 also! I did have one issues with copy/pasting the build string so you might want to warn readers of this. I think it was messing with the single-quotes. Either way I finally decided to try typing it all out instead of copy/paste and it worked great!

    I now have one question. Is it possible to save these settings as a template or something. This way I can click New->Project and then from the list of options have a NDS option. I’m a bit lazy (i think most coders are..) and going through all of these steps is a bit much every time I want to start up a new NDS homebrew. :)

    Thanks loads!

  17. coderjoe Says:

    @Holland

    I’m glad I could help. Unfortunately I can’t help you with a template, I’ve since switched all my development into a Linux based environment. However, if you do manage to make a Visual Studio template I’d be happy to link to it here.

    Cheers.

  18. meta cog Says:

    Does this work in VS2008?

    If I try to build the hello world example, I get this error…

    1>Project : error PRJ0002 : Error result 255 returned from ‘C:\Windows\SysWow64\cmd.exe’.

    Could that be because it can’t find “sed” or “make” as commands? (I’m using Visual Studio 2008 Express, on Vista-64, if that matters)
    If I open command prompt and type make, it says it’s not an internal or external command. do I need to install Cygwin or something, or am I like, WAY off?

    I admit that I don’t really understand how projects are configured at all, I’m used to C# not C… However, all the tutorials that I have seen so far, mention that same command string, which is the part that I think is giving me a problem.
    The Build Command line uses cmd.exe right, so it’s basically only able to use dos commands, that means that sed and make should not work in it without some sort of extra piece of software right? The thing is, nobody mentions anything of the sort, and seems to imply that they should just already be present… (and I have no idea if cygwin would even work for that or not)

    Am I missing something?

  19. coderjoe Says:

    If you’re running on windows, the devkitPro installer should have automatically installed the necessary components required to build your project.
    I believe these tools are listed as “Minimal Components” or something like that.
    Re-run the updater and do not deselect these critical components.

    Cheers.

  20. meta cog Says:

    Thanks for the reply! It’s working now. Turns out all I needed to do was re-boot… -_-

    The project builds and I can get it to run on the DeSmuME emulator! (But not Dualis, for some reason).

    I’ve read on another article that you recommend PAlib, so I think I’ll try that.

    Thanks a bunch!

  21. Bacioiu Ciprian Says:

    I copied everything as you said, but when I type in Make in the CMD, it outputs the following:
    1>Performing Makefile project actions
    1>basename: extra operand `Settings/Bacioiu’
    1>Try `basename –help’ for more information.
    1>make[1]: /c/Documents: No such file or directory
    1>make[1]: *** No rule to make target `/c/Documents’. Stop.
    1>make: *** [build] Error 2
    1>Build log was saved at “file://c:\Documents and Settings\Bacioiu Ciprian\My Documents\Visual Studio 2008\Projects\reaction\Debug\BuildLog.htm”
    1>Reaction – 0 error(s), 0 warning(s)

    Thing is, it works if i Don’t actually copy the template to another folder, and make the project there! Any idea why this is happening?

Leave a Reply