Difference between revisions of "Setting up Development Environment"

From 3dbrew
Jump to navigation Jump to search
(43 intermediate revisions by 17 users not shown)
Line 1: Line 1:
 
= Setup =
 
= Setup =
* Install [http://devkitpro.org/ devkitARM]. If it's already installed, update it. On Windows there's a GUI installer. On Linux/Mac there's a perl-script. Make sure you also select ctrulib when installing.
+
* Install [https://devkitpro.org/ devkitARM]. If it's already installed, update it.
* Download the files in the [https://github.com/smealum/ctrulib/archive/master.zip ctrulib repository] (even though the library has already been installed) because the repository contains a 3DS project template and examples.
+
** On Windows, there's a [https://github.com/devkitPro/installer/releases/latest graphical installer].
 +
** On Unix-like platforms such as Linux/macOS, there's a [https://raw.githubusercontent.com/devkitPro/installer/master/perl/devkitARMupdate.pl Perl script]. Make sure you also select libctru and the 3ds examples when installing.
 
* Depending on the kind of homebrew you want to develop, you may be interested in installing and using additional libraries and tools which don't ship alongside devkitARM/libctru. A list of them can be found in [[Homebrew Libraries and Tools]].
 
* Depending on the kind of homebrew you want to develop, you may be interested in installing and using additional libraries and tools which don't ship alongside devkitARM/libctru. A list of them can be found in [[Homebrew Libraries and Tools]].
  
==Linux==
+
==Windows==
* First get the devkitARM updater Perl script for Linux.
+
devkitPro provides Win32-native precompiled versions of devkitARM which can be run directly on Windows.
* Run it with superuser privileges if your /opt directory is not marked world read-writeable.
+
* [https://github.com/devkitPro/installer/releases/latest download the latest version of the graphical installer] from SourceForge and run it, following the instructions as you go.
* Get ctrulib from Smealum's GitHub repository, build and install it.
+
* An Internet connection is required.
 +
* You will want to make sure devkitARM is selected during the installation process to develop for the 3DS (and also the DS and GBA) - you can also install devkitPPC (for GameCube/Wii development) and devkitPSP (for PlayStation Portable development) if you wish.
 +
* Once the installer has finished, launch MSYS from:
 +
** Windows 7 and earlier: Start -> All Programs -> devkitPro -> MSYS
 +
** Windows 8 and 8.1: Right click on the Start screen and select 'All Apps'. You should find MSYS there.
 +
** Windows 10 (pre-Anniversary Update): Start -> All Apps -> devkitPro -> MSYS
 +
** Windows 10 (post-Anniversary Update): Start -> devkitPro -> MSYS
  
<pre>sudo apt-get install git curl
+
Alternatively starting with Windows 10 Anniversary Update (Version 1607), the [https://msdn.microsoft.com/en-us/commandline/wsl/install_guide Windows Subsystem for Linux (WSL)] may also be used to run the Linux version of devkitARM. Unless you have some particular need for WSL it's recommended that you stick to a more standard environment.
curl -L http://sourceforge.net/projects/devkitpro/files/Automated%20Installer/devkitARMupdate.pl/download -o devkitARMupdate.pl
+
 
 +
==Unix-like platforms==
 +
Currently devkitPro provides precompiled versions of devkitARM for the following Unix-like platforms: Linux (x86_64), macOS (x86_64). Note that Linux x86_64 binaries are usable under WSL.
 +
 
 +
* First, you need to install curl so the installer can download the devkitARM packages, and you should also install Git - you'll need it to update libctru or share your code on GitHub, among many other things. If you are running Linux, you'll also need wget; it comes preinstalled on most distributions, but not all.
 +
 
 +
* Find your way into a shell (eg. by opening a Terminal window), and follow the instructions for your OS:
 +
** Debian/Ubuntu/Linux Mint/Ubuntu on WSL: <code>sudo apt-get install git curl</code>
 +
** Fedora/CentOS/RHEL: <code>sudo yum install git curl</code>
 +
** openSUSE: <code>sudo zypper install git curl</code>
 +
** Arch Linux/ALWSL: <code>sudo pacman -S git curl wget</code>
 +
** macOS: Download Git from [http://git-scm.com/download/mac] and install it. Curl is included with the OS.
 +
 
 +
* Next, we need to download, make executable and run the devkitARM updater (don't worry, the updater is also the installer.)
 +
<pre>
 +
curl -L https://raw.githubusercontent.com/devkitPro/installer/master/perl/devkitARMupdate.pl -o devkitARMupdate.pl
 
chmod +x ./devkitARMupdate.pl
 
chmod +x ./devkitARMupdate.pl
sudo -s
+
./devkitARMupdate.pl
./devkitARMupdate.pl /opt/devkitpro
 
cd /opt/devkitpro
 
git clone https://github.com/smealum/ctrulib.git
 
cd ctrulib/libctru
 
export DEVKITPRO=/opt/devkitpro
 
export DEVKITARM=$DEVKITPRO/devkitARM
 
make
 
make install
 
exit
 
echo "export DEVKITPRO=/opt/devkitpro" >> ~/.bashrc
 
echo "export DEVKITARM=$DEVKITPRO/devkitARM" >> ~/.bashrc
 
echo "export PATH=$PATH:$DEVKITARM/bin" >> ~/.bashrc
 
source ~/.bashrc
 
 
</pre>
 
</pre>
 +
 +
You can either use sudo here or chown /opt/devkitpro to be writable by your user before running the script.
  
 
= Building the examples =
 
= Building the examples =
3DS examples are still being created. Currently there are a few examples in the separate ctrulib download under the "examples" folder.
+
3DS examples are still being created; however, there are a growing number of examples available from the [https://github.com/devkitPro/3ds-examples devkitPro/3ds-examples GitHub repository].
 +
There are now too many to list here in detail, so go ahead and browse them.
 +
 
 +
* To download these, if you installed Git (as you will have if you followed the above instructions), simply type <code>git clone https://github.com/devkitPro/3ds-examples.git</code> into your shell in the directory you wish to store the 3ds-examples folder in.
 +
 
 +
These can be built from the command line.
 +
 
 +
To start a new homebrew project from the <code>bash</code> shell, simply type the following (replacing <code>'''~/projects/my3dsproject'''</code> with the place you would like your project to be stored, with <code>~</code> meaning your HOME directory):
 +
cp -r $DEVKITPRO/examples/3ds/templates/application '''~/projects/my3dsproject'''
 +
cd '''~/projects/my3dsproject'''
 +
 
 +
The standard Makefile will use the folder as the name of the 3dsx that will be built. You can keep that behaviour or simply change the <code>TARGET := $(notdir $(CURDIR))</code> line in the Makefile to explicitly name your project.
 +
 
 +
To compile it, type <code>make</code> in the project directory.
 +
 
 +
==Running your code==
 +
To run it on your 3DS, start the Homebrew Launcher, press Y to open the network loader, then on your PC type: <code>$DEVKITARM/bin/3dslink  '''my3dsproject'''.3dsx</code>, replacing '''my3dsproject''' with the name of the 3dsx file you want to run.)
  
* '''arm11u:''' simple homebrew example
+
If all goes well, you'll soon see your application running on your 3DS.
* '''sdmc:''' demonstrates how to access files on the SD card
 
* '''mic:''' demonstrates how to read sound from the microphone
 
* '''gpu:''' demonstrates how to render 3D geometry with the GPU
 
  
 
==Building the examples on Linux with Netbeans==
 
==Building the examples on Linux with Netbeans==
Line 46: Line 70:
 
* Right-click the project and go to Properties->Code Assistance and click C Compiler.
 
* Right-click the project and go to Properties->Code Assistance and click C Compiler.
 
* In include directories enter  
 
* In include directories enter  
<pre>/opt/devkitpro/devkitARM/include;/opt/devkitpro/ctrulib/libctru/include</pre>
+
<pre>/opt/devkitpro/devkitARM/include;/opt/devkitpro/libctru/include</pre>
 
adjusting again for your devkitPro path.
 
adjusting again for your devkitPro path.
 
* Do the same for 'C++ Compiler'.
 
* Do the same for 'C++ Compiler'.
Line 54: Line 78:
 
Now you can use Netbeans' code completion feature and build your project from the Run menu.
 
Now you can use Netbeans' code completion feature and build your project from the Run menu.
  
= Building homebrew for distribution =
+
= Troubleshooting =
To build your homebrew open a terminal, browse to your homebrew's folder and run make.
+
'''I get the "Please set DEVKITARM in your environment." error.'''
  
* This will build a .elf file and a .3dsx file together with an icon. The icon and .3dsx file are the format required for the [[Homebrew Channel]].
+
Use the following command before installing [http://askubuntu.com/questions/573070/problem-setting-up-environment-for-make-command-execution]:
 +
sudo chown $USER /opt/devkitpro/ -R
 +
echo "export DEVKITPRO=\"/opt/devkitpro/\"" >> ~/.profile
 +
echo "export DEVKITARM=\"\${DEVKITPRO}/devkitARM/\"" >> ~/.profile
 +
source ~/.profile
  
* To build a Gateway-compatible .3ds file you need to strip the .elf file and use makerom on it (with the provided RSF file):
+
For WSL users, you need to close the Bash shell, then reopen it for WSL to reload all of the variables from a clean state.
arm-none-eabi-strip [ELF file]
 
makerom -f cci -o [.3ds file] -rsf [RSF file] -target d -exefslogo -elf [ELF file] -icon [icon file] -banner [banner file]
 

Revision as of 17:25, 17 April 2018

Setup

  • Install devkitARM. If it's already installed, update it.
    • On Windows, there's a graphical installer.
    • On Unix-like platforms such as Linux/macOS, there's a Perl script. Make sure you also select libctru and the 3ds examples when installing.
  • Depending on the kind of homebrew you want to develop, you may be interested in installing and using additional libraries and tools which don't ship alongside devkitARM/libctru. A list of them can be found in Homebrew Libraries and Tools.

Windows

devkitPro provides Win32-native precompiled versions of devkitARM which can be run directly on Windows.

  • download the latest version of the graphical installer from SourceForge and run it, following the instructions as you go.
  • An Internet connection is required.
  • You will want to make sure devkitARM is selected during the installation process to develop for the 3DS (and also the DS and GBA) - you can also install devkitPPC (for GameCube/Wii development) and devkitPSP (for PlayStation Portable development) if you wish.
  • Once the installer has finished, launch MSYS from:
    • Windows 7 and earlier: Start -> All Programs -> devkitPro -> MSYS
    • Windows 8 and 8.1: Right click on the Start screen and select 'All Apps'. You should find MSYS there.
    • Windows 10 (pre-Anniversary Update): Start -> All Apps -> devkitPro -> MSYS
    • Windows 10 (post-Anniversary Update): Start -> devkitPro -> MSYS

Alternatively starting with Windows 10 Anniversary Update (Version 1607), the Windows Subsystem for Linux (WSL) may also be used to run the Linux version of devkitARM. Unless you have some particular need for WSL it's recommended that you stick to a more standard environment.

Unix-like platforms

Currently devkitPro provides precompiled versions of devkitARM for the following Unix-like platforms: Linux (x86_64), macOS (x86_64). Note that Linux x86_64 binaries are usable under WSL.

  • First, you need to install curl so the installer can download the devkitARM packages, and you should also install Git - you'll need it to update libctru or share your code on GitHub, among many other things. If you are running Linux, you'll also need wget; it comes preinstalled on most distributions, but not all.
  • Find your way into a shell (eg. by opening a Terminal window), and follow the instructions for your OS:
    • Debian/Ubuntu/Linux Mint/Ubuntu on WSL: sudo apt-get install git curl
    • Fedora/CentOS/RHEL: sudo yum install git curl
    • openSUSE: sudo zypper install git curl
    • Arch Linux/ALWSL: sudo pacman -S git curl wget
    • macOS: Download Git from [1] and install it. Curl is included with the OS.
  • Next, we need to download, make executable and run the devkitARM updater (don't worry, the updater is also the installer.)
curl -L https://raw.githubusercontent.com/devkitPro/installer/master/perl/devkitARMupdate.pl -o devkitARMupdate.pl
chmod +x ./devkitARMupdate.pl
./devkitARMupdate.pl

You can either use sudo here or chown /opt/devkitpro to be writable by your user before running the script.

Building the examples

3DS examples are still being created; however, there are a growing number of examples available from the devkitPro/3ds-examples GitHub repository. There are now too many to list here in detail, so go ahead and browse them.

  • To download these, if you installed Git (as you will have if you followed the above instructions), simply type git clone https://github.com/devkitPro/3ds-examples.git into your shell in the directory you wish to store the 3ds-examples folder in.

These can be built from the command line.

To start a new homebrew project from the bash shell, simply type the following (replacing ~/projects/my3dsproject with the place you would like your project to be stored, with ~ meaning your HOME directory):

cp -r $DEVKITPRO/examples/3ds/templates/application ~/projects/my3dsproject
cd ~/projects/my3dsproject

The standard Makefile will use the folder as the name of the 3dsx that will be built. You can keep that behaviour or simply change the TARGET := $(notdir $(CURDIR)) line in the Makefile to explicitly name your project.

To compile it, type make in the project directory.

Running your code

To run it on your 3DS, start the Homebrew Launcher, press Y to open the network loader, then on your PC type: $DEVKITARM/bin/3dslink my3dsproject.3dsx, replacing my3dsproject with the name of the 3dsx file you want to run.)

If all goes well, you'll soon see your application running on your 3DS.

Building the examples on Linux with Netbeans

  • Go to File->New Project...
  • Select C/C++ Project with existing code
  • Navigate to the examples directory and select the folder for the project you want to build; eg. /home/vtsingaras/3ds/examples/app_launch
  • Leave Configuration Mode to 'Automatic' and click 'Finish'.
  • It will fail to build. Now edit Makefile and insert these two lines, adjusting for your devkitpro path, at the top:
export DEVKITPRO=/opt/devkitpro
export DEVKITARM=/opt/devkitpro/devkitARM
  • Right-click the project and go to Properties->Code Assistance and click C Compiler.
  • In include directories enter
/opt/devkitpro/devkitARM/include;/opt/devkitpro/libctru/include

adjusting again for your devkitPro path.

  • Do the same for 'C++ Compiler'.
  • Go to 'Run' and click 'Clean and Build Project'.
  • Now right-click on the project and select Code Assistance->Reparse Project.

Now you can use Netbeans' code completion feature and build your project from the Run menu.

Troubleshooting

I get the "Please set DEVKITARM in your environment." error.

Use the following command before installing [2]:

sudo chown $USER /opt/devkitpro/ -R
echo "export DEVKITPRO=\"/opt/devkitpro/\"" >> ~/.profile
echo "export DEVKITARM=\"\${DEVKITPRO}/devkitARM/\"" >> ~/.profile
source ~/.profile

For WSL users, you need to close the Bash shell, then reopen it for WSL to reload all of the variables from a clean state.