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.

  1. Download our Windows toolchain for Raspberry PI and install it by running the installer.
  2. If you have not prepared the SD card yet, download and unpack the SD card image.
  3. Go to the directory where you have installed the toolchain and run tools\WinFLASHTool.exe.
  4. Specify the path to the SD card image you have downloaded and unpacked.
  5. Insert your SD card into the card reader and select it in the list:
  6. 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:
  7. Wait until WinFLASHTool finishes writing the image to your SD card. Writing the SD card typically takes several minutes depending on the card speed:
  8. 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:
  9. 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.
  10. 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:

  1. 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;
    }
  2. Build the file by running the following command from Windows command-line:
    <toolchain>\bin\arm-linux-gnueabihf-g++.exe -ggdb test.cpp -o test
    Verify that the file called "test" has been created in the same directory as test.cpp.
  3. Open the directory where you have installed the toolchain. Run Tools\PortableSmartty\SmarTTY.exe
  4. 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
  5. Press Connect and confirm the key fingerprint. A new SSH window will be opened:
  6. Drag the previously created test file into the SmarTTY window or use the SCP->Upload file command.
  7. Run the following commands to test the executable:
    chmod a+x test
    ./test
  8. Now we can test remote debugging with GDB. Run the following command in the Raspberry PI shell:
    gdbserver :1234 test
    This will start the test executable under debugger waiting connections on port 1234.
  9. On your Windows machine run gdb provided with the toolchain:
    <toolchain>\bin\arm-linux-gnueabihf-gdb.exe test
  10. 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
  11. Once a breakpoint in main() is hit, execute the n command to step to the next line:
  12. Once you execute the n command in GDB, you will see the "Hello, world" line printed in SmarTTY window: