Tutorial: building Raspberry PI apps from Windows
This tutorial shows how to build and debug a "Hello world" application for Raspberry PI on Windows. It includes initial installation and SD card preparation.
- Download our Windows toolchain for Raspberry PI and install it by running the installer.
- If you have not prepared the SD card yet, download and unpack the SD card image.
- Go to the directory where you have installed the toolchain and run tools\WinFLASHTool.exe.
- Specify the path to the SD card image you have downloaded and unpacked.
- Insert your SD card into the card reader and select it in the list:
- Press the Write button. Double-check the information in the confirmation dialog to avoid confusing the SD card with another storage device and rewriting it by mistake:
- Wait until WinFLASHTool finishes writing the image to your SD card. Writing the SD card typically takes several minutes depending on the card speed:
- Insert the SD card into the slot on the Raspberry PI board. Connect the network cable. Optionally connect the keyboard and the HDMI cable. Finally connect the power cable and let the board start:
- Use the keyboard/screen (ifconfig command) or the DHCP status viewer of your router to find out the IP address of the Raspberry PI board. In this tutorial it is 192.168.0.100.
- Before you start using your toolchain it is highly recommended to update the cross-compiler sysroot.
Congratulations. You have managed to setup your Raspbery PI board. If you have Visual Studio installed, follow this tutorial to build your app with Visual Studio.
If you don't want to use Visual Studio, you can make your project with the command-line tools:
- Create a temporary folder and make a new file called
test.cpp. Enter the folllowing contents
into it:#include <stdio.h>
int main()
{
printf("Hello, world\n");
return 0;
} - Build the file by running the following command from
Windows command-line:<toolchain>\bin\arm-linux-gnueabihf-g++.exe -ggdb test.cpp -o testVerify that the file called "test" has been created in the same directory as test.cpp.
- Open the directory where you have installed the toolchain. Run Tools\PortableSmartty\SmarTTY.exe
- Enter the following parameters to connect to the
Raspberry PI board:
Host name The IP address of the board User name pi Password raspberry Setup public key yes - Press Connect and confirm the key fingerprint. A new SSH window will be opened:
- Drag the previously created test file into the SmarTTY window or use the SCP->Upload file command.
- Run the following commands to test the executable:chmod a+x test
./test - Now we can test remote debugging with GDB. Run the
following command in the Raspberry PI shell:gdbserver :1234 testThis will start the test executable under debugger waiting connections on port 1234.
- On your Windows machine run gdb provided with the
toolchain:<toolchain>\bin\arm-linux-gnueabihf-gdb.exe test
- Enter the following commands in GDB to connect to
Raspberry PI and start debugging your program:target remote <Raspberry IP address>:1234
b main
c - Once a breakpoint in main() is hit, execute the n command to step to the next line:
- Once you execute the n command in GDB, you will see the "Hello, world" line printed in SmarTTY window: