Homebrew Misc Setting up Visual Studio Code for libnds and devkitPro?

OM3GAZX

Active Member
OP
Newcomer
Joined
Sep 4, 2021
Messages
44
Trophies
0
Location
Deep Log
XP
299
Country
Mexico
As stated above, I'm trying to get into DS programming by using Visual Studio Code and the good ol' devkitPro. However, the guides for programming on the Nintendo DS are extremely limited as of now, so far I've only been able to find these ones, which seem pretty decent:

DS Programming for Newbies! (2012)
Introduction to DS Programming (2008?)

The second one seems to be more complete so far. The first one seems to have a rather outdated setup, so I decided to follow @Pk11's recommended setup, which is as follows (source):
I assume you mean DS Programming for Newbies! as the tutorial?

You can install devkitPro's toolchains using the installers linked from their getting started page. You can download the latest Visual Studio from https://visualstudio.microsoft.com or the link in that guide still seems to work for 2008, the wizard to add DS projects isn't even on archive.org though...

Their recommended setup is rather out of date though saying as the tutorial is from 2012, what I personally use for DS homebrew is:
- devkitPro's nds-dev toolchain which can be installed using pacman, install pacman using the method for your OS from their getting started page
- Visual Studio Code

-- You can use any text editor or full Visual Studio if you want, this is my personal favorite for DS projects though as its cross platform and works quite well, probably a nicer experience than Visual Studio 2008, just run 'make' from the terminal to build things instead of pressing F7
- If you want you should be able to use NightFox Lib too, I think it still works, I haven't used it myself though
After installing Visual Studio Code, I stumbled across many issues with it, such as Visual Studio Code not detecting the dependencies for the nds.h file (I installed devkitPro at my C: drive, if you ask), and no knowledge on how to directly debug my program.

If anybody has a Visual Studio Code setup with devkitPro, please let me know on how to do that.
I have absolutely no knowledge in programming (except for some knowledge in BASIC and Bash), so please try to explain me on how to setup this in the simplest and dumbest way possible.

Thanks in advance.
 

Pk11

A catgirl with a DSi
Member
Joined
Jun 26, 2019
Messages
1,286
Trophies
1
Age
23
Location
米国
Website
xn--rck9c.xn--tckwe
XP
3,934
Country
United States
Make sure to install the C/C++ extension, then this is what I use for its config:
JSON:
    "C_Cpp.default.includePath": [
        "${workspaceFolder}/**",
        "/opt/devkitpro/libnds/include/**",
        "/opt/devkitpro/libctru/include/**",
        "/opt/devkitpro/devkitARM/include/**",
        "/opt/devkitpro/devkitARM/arm-none-eabi/include/**"
    ],
    "C_Cpp.default.defines": [
        "ARM9"
    ],
    "C_Cpp.default.compilerPath": "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc",
    "C_Cpp.default.intelliSenseMode": "macos-gcc-x64",

On Windows you'll probably want something more like:
JSON:
    "C_Cpp.default.includePath": [
        "${workspaceFolder}\\**",
        "C:\\devkitPro\\libnds\\include\\**",
        "C:\\devkitPro\\libctru\\include\\**",
        "C:\\devkitPro\\devkitARM\\include\\**",
        "C:\\devkitPro\\devkitARM\\arm-none-eabi\\include\\**"
    ],
    "C_Cpp.default.defines": [
        "ARM9"
    ],
    "C_Cpp.default.compilerPath": "C:\\devkitPro\\devkitARM\\bin\\arm-none-eabi-gcc",
    "C_Cpp.default.intelliSenseMode": "windows-gcc-x64",

If you open VS Code settings (command/ctrl + comma) then click the
スクリーンショット 0004-07-08 16.57.47.png
button in the top right it'll open the settings as JSON and you can paste in what I put above, and edit as needed.

Notes:
  • The libctru line isn't needed for DS development, it's for 3DS, but I do 3DS sometimes too and figure others might as well so I left it in
  • The ARM9 define helps some libnds headers be recognized correctly as they lock their content between ARM9 and ARM7 defines. The vast majority of DS code is for ARM9 so I just leave it as that typically, but if you find yourself writing ARM7 code you may want to switch it to ARM7
  • Honestly not sure what the C_Cpp.default.intelliSenseMode does, I just set it to the one that makes sense for my OS, might make more sense to use linux arm or so idk
 

Necron

Lurking~
Member
Joined
Dec 29, 2008
Messages
1,100
Trophies
1
Location
Mi casa
XP
2,522
Country
Chile
Make sure to install the C/C++ extension, then this is what I use for its config:
JSON:
    "C_Cpp.default.includePath": [
        "${workspaceFolder}/**",
        "/opt/devkitpro/libnds/include/**",
        "/opt/devkitpro/libctru/include/**",
        "/opt/devkitpro/devkitARM/include/**",
        "/opt/devkitpro/devkitARM/arm-none-eabi/include/**"
    ],
    "C_Cpp.default.defines": [
        "ARM9"
    ],
    "C_Cpp.default.compilerPath": "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc",
    "C_Cpp.default.intelliSenseMode": "macos-gcc-x64",

On Windows you'll probably want something more like:
JSON:
    "C_Cpp.default.includePath": [
        "${workspaceFolder}\\**",
        "C:\\devkitPro\\libnds\\include\\**",
        "C:\\devkitPro\\libctru\\include\\**",
        "C:\\devkitPro\\devkitARM\\include\\**",
        "C:\\devkitPro\\devkitARM\\arm-none-eabi\\include\\**"
    ],
    "C_Cpp.default.defines": [
        "ARM9"
    ],
    "C_Cpp.default.compilerPath": "C:\\devkitPro\\devkitARM\\bin\\arm-none-eabi-gcc",
    "C_Cpp.default.intelliSenseMode": "windows-gcc-x64",

If you open VS Code settings (command/ctrl + comma) then click the View attachment 317212 button in the top right it'll open the settings as JSON and you can paste in what I put above, and edit as needed.

Notes:
  • The libctru line isn't needed for DS development, it's for 3DS, but I do 3DS sometimes too and figure others might as well so I left it in
  • The ARM9 define helps some libnds headers be recognized correctly as they lock their content between ARM9 and ARM7 defines. The vast majority of DS code is for ARM9 so I just leave it as that typically, but if you find yourself writing ARM7 code you may want to switch it to ARM7
  • Honestly not sure what the C_Cpp.default.intelliSenseMode does, I just set it to the one that makes sense for my OS, might make more sense to use linux arm or so idk
Nice guide! was thinking of doing some stuff on vscode for the DS, so this will save me lots of time.
About the intelisense, I guess it's just to check the warnings? cause the platform needs to be specified.
 

godreborn

Welcome to the Machine
Member
Joined
Oct 10, 2009
Messages
38,467
Trophies
3
XP
29,282
Country
United States
Personally, I just make changes to code in vsc, and compile in cmd prompt through devkitPro. Nds should be fine with cmd prompt. I only have issues with the ps4, so I compile those in Linux. Just remember to add certain Libraries to environmental variables like @Pk11 mentioned.
 

OM3GAZX

Active Member
OP
Newcomer
Joined
Sep 4, 2021
Messages
44
Trophies
0
Location
Deep Log
XP
299
Country
Mexico
Make sure to install the C/C++ extension, then this is what I use for its config:
JSON:
    "C_Cpp.default.includePath": [
        "${workspaceFolder}/**",
        "/opt/devkitpro/libnds/include/**",
        "/opt/devkitpro/libctru/include/**",
        "/opt/devkitpro/devkitARM/include/**",
        "/opt/devkitpro/devkitARM/arm-none-eabi/include/**"
    ],
    "C_Cpp.default.defines": [
        "ARM9"
    ],
    "C_Cpp.default.compilerPath": "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc",
    "C_Cpp.default.intelliSenseMode": "macos-gcc-x64",

On Windows you'll probably want something more like:
JSON:
    "C_Cpp.default.includePath": [
        "${workspaceFolder}\\**",
        "C:\\devkitPro\\libnds\\include\\**",
        "C:\\devkitPro\\libctru\\include\\**",
        "C:\\devkitPro\\devkitARM\\include\\**",
        "C:\\devkitPro\\devkitARM\\arm-none-eabi\\include\\**"
    ],
    "C_Cpp.default.defines": [
        "ARM9"
    ],
    "C_Cpp.default.compilerPath": "C:\\devkitPro\\devkitARM\\bin\\arm-none-eabi-gcc",
    "C_Cpp.default.intelliSenseMode": "windows-gcc-x64",

If you open VS Code settings (command/ctrl + comma) then click the View attachment 317212 button in the top right it'll open the settings as JSON and you can paste in what I put above, and edit as needed.

Notes:
  • The libctru line isn't needed for DS development, it's for 3DS, but I do 3DS sometimes too and figure others might as well so I left it in
  • The ARM9 define helps some libnds headers be recognized correctly as they lock their content between ARM9 and ARM7 defines. The vast majority of DS code is for ARM9 so I just leave it as that typically, but if you find yourself writing ARM7 code you may want to switch it to ARM7
  • Honestly not sure what the C_Cpp.default.intelliSenseMode does, I just set it to the one that makes sense for my OS, might make more sense to use linux arm or so idk
Thanks a lot for the configuration, @Pk11!
I have a not-so-small problem now.
It seems like the GCC compiler you're using isn't detecting the nds.h file for some weird reason. I have it on the libnds\include directory, so there must be a reason it doesn't want to detect it.
This problem is kinda annoying, as I can't compile my program to debug it and search for errors.

Below this post I attached two images so you can verify what's wrong with it.
Thanks in advance!
 

Attachments

  • Screenshot 2022-07-09 194921.png
    Screenshot 2022-07-09 194921.png
    70.4 KB · Views: 168
  • Screenshot 2022-07-09 194954.png
    Screenshot 2022-07-09 194954.png
    63.1 KB · Views: 186

Pk11

A catgirl with a DSi
Member
Joined
Jun 26, 2019
Messages
1,286
Trophies
1
Age
23
Location
米国
Website
xn--rck9c.xn--tckwe
XP
3,934
Country
United States
Thanks a lot for the configuration, @Pk11!
I have a not-so-small problem now.
It seems like the GCC compiler you're using isn't detecting the nds.h file for some weird reason. I have it on the libnds\include directory, so there must be a reason it doesn't want to detect it.
This problem is kinda annoying, as I can't compile my program to debug it and search for errors.

Below this post I attached two images so you can verify what's wrong with it.
Thanks in advance!
I don't use the "build active file" option so not sure how you'd do that, if it's even possible... What I do is just open the integrated terminal (command + ` on macOS) and run make (or often make -s -j$(nproc)).

If you don't want to have to run make like that you can set up a build task, I've still got the file I used to use in pkmn-chest's repo, I found that more annoying than just running make though so I don't do it anymore.

Its debugger isn't going to be able to help for DS programs, for debugging I usually just use nocashMessage() prints if I can use no$gba, or otherwise just printf or the equivalent GUI function of whatever I'm working on.
 
  • Like
Reactions: Zense

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,045
Trophies
1
XP
3,112
Country
United States
Thanks a lot for the configuration, @Pk11!
I have a not-so-small problem now.
It seems like the GCC compiler you're using isn't detecting the nds.h file for some weird reason. I have it on the libnds\include directory, so there must be a reason it doesn't want to detect it.
This problem is kinda annoying, as I can't compile my program to debug it and search for errors.

Below this post I attached two images so you can verify what's wrong with it.
Thanks in advance!
The tools on windows do not like paths with spaces.
It also appears to be trying to build an exe instead of a nds file. Are you trying to compile by running make against a standard devkitpro makefile or are you trying to do something else?
 
Last edited by elhobbs,

OM3GAZX

Active Member
OP
Newcomer
Joined
Sep 4, 2021
Messages
44
Trophies
0
Location
Deep Log
XP
299
Country
Mexico
I don't use the "build active file" option so not sure how you'd do that, if it's even possible... What I do is just open the integrated terminal (command + ` on macOS) and run make (or often make -s -j$(nproc)).

If you don't want to have to run make like that you can set up a build task, I've still got the file I used to use in pkmn-chest's repo, I found that more annoying than just running make though so I don't do it anymore.

Its debugger isn't going to be able to help for DS programs, for debugging I usually just use nocashMessage() prints if I can use no$gba, or otherwise just printf or the equivalent GUI function of whatever I'm working on.
After a little research, it looks like the tasks.json configuration file is what is in charge of the compilation instructions (according to this), hence why it's refusing to read the nds.h file.
I'll try to run the "make" command from the terminal and see what happens.

The tools on windows do not like paths with spaces.
Oops, just learned that Windows doesn't like spaces :mellow:
I'll try to rename the "Nintendo DS" part to "DS", if that solves the problem.
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,045
Trophies
1
XP
3,112
Country
United States
After a little research, it looks like the tasks.json configuration file is what is in charge of the compilation instructions (according to this), hence why it's refusing to read the nds.h file.
I'll try to run the "make" command from the terminal and see what happens.


Oops, just learned that Windows doesn't like spaces :mellow:
I'll try to rename the "Nintendo DS" part to "DS", if that solves the problem.
Also try to compile from the msys command line using make. It is not clear if you have all of the components installed for compiling for nds.
 

Pk11

A catgirl with a DSi
Member
Joined
Jun 26, 2019
Messages
1,286
Trophies
1
Age
23
Location
米国
Website
xn--rck9c.xn--tckwe
XP
3,934
Country
United States
One question, how do I compile a file from msys?
I know its a dumb question, but I'm really new to this.
You just cd to the folder and run make, like this:
Bash:
cd /Proyectos/DS/hello-world
make
(note: I'm not sure if the C drive is actually mapped to root, it might be /mnt/c/Proyectos or something like that?)

Though looking back at your image I see your .cpp file seems to be in the root of the project, that probably won't work. You need to have a proper Makefile and project layout you can't just run gcc and get an NDS file.

When starting a new project you should copy one of the devkitPro templates, the arm9 template is generally best since most projects don't need custom ARM7 code, if you do use "combined". It may also be easier to just copy a relevant example from that same repo. (or the examples are also installable from pacman) The prj and pnprj files aren't needed, only the Makefile and source folder are important.
 
  • Like
Reactions: OM3GAZX

OM3GAZX

Active Member
OP
Newcomer
Joined
Sep 4, 2021
Messages
44
Trophies
0
Location
Deep Log
XP
299
Country
Mexico
You just cd to the folder and run make, like this:
Bash:
cd /Proyectos/DS/hello-world
make
(note: I'm not sure if the C drive is actually mapped to root, it might be /mnt/c/Proyectos or something like that?)

Though looking back at your image I see your .cpp file seems to be in the root of the project, that probably won't work. You need to have a proper Makefile and project layout you can't just run gcc and get an NDS file.

When starting a new project you should copy one of the devkitPro templates, the arm9 template is generally best since most projects don't need custom ARM7 code, if you do use "combined". It may also be easier to just copy a relevant example from that same repo. (or the examples are also installable from pacman) The prj and pnprj files aren't needed, only the Makefile and source folder are important.
So, I just need to use one of those templates and I'm done with it?
I'll probably test it when I'm back home.
Thanks for the info, @Pk11!
 
  • Like
Reactions: Pk11

OM3GAZX

Active Member
OP
Newcomer
Joined
Sep 4, 2021
Messages
44
Trophies
0
Location
Deep Log
XP
299
Country
Mexico
I can confirm that running make from Visual Studio Code's terminal works, and I can properly debug my program from melonDS.
The program was built without any issues, and the template you provided to me works flawlessly.
I owe you one!
 

Attachments

  • Screenshot 2022-07-11 164149.png
    Screenshot 2022-07-11 164149.png
    4.3 KB · Views: 173
  • Like
Reactions: RocketRobz and Pk11

Pk11

A catgirl with a DSi
Member
Joined
Jun 26, 2019
Messages
1,286
Trophies
1
Age
23
Location
米国
Website
xn--rck9c.xn--tckwe
XP
3,934
Country
United States
I can confirm that running make from Visual Studio Code's terminal works, and I can properly debug my program from melonDS.
The program was built without any issues, and the template you provided to me works flawlessly.
I owe you one!
fyi no$gba has a lot more debugging features than melonDS and also supports DSi mode homebrew. You can use nocashMessage or fprintf to stderr when the debug output is set correctly and it'll print to a special debug area (Window -> TTY Debug Messages), the VRAM and RAM viewers can be handy, etc.

MelonDS is also a good emulator, I just tend to prefer no$gba for homebrew development.
 
  • Like
Reactions: OM3GAZX

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    The Real Jdbye @ The Real Jdbye: must be a different ken +1