Using a Cross-compiler for Raspberry PI

This tutorial shows how to develop for Raspberry PI using a cross compiler in Visual Studio.

Before we begin, ensure that VisualGDB 3.0 or later is installed.

  1. Start Visual Studio. Go to File->New->Project and select VisualGDB->Linux Project Wizard. Choose a name and location for the project and press ‘OK’ when done. 01-newproject
  2. Choose ‘Create a new project’ and press on ‘Next’. 02-newlinux
  3. Choose ‘Build the project locally with a cross-compiler. For the cross-toolchain choose ‘Raspberry PI’. 03-raspberry
  4. Choose the toolchain to be downloaded and installed. 04-toolchain
  5. Accept the toolchain license and press on ‘Install’. The toolchain will then be downloaded and installed. 05-toolchaininstall06-installing
  6. Once the installation of the toolchain completes, choose the raspberry board for the deployment computer. Create a new SSH connection for it. 07-newconnection
  7. Choose the hostname or ip of the board together with the user name and password. Here we use the default user name pi and password raspberry. It is recommended to check the “setup public key” checkbox, so that VisualGDB will automatically generate an public/private keypair, store it in your Windows account’s key container and setup the Raspberry PI box to use it. Press on ‘Create’ to make the connection. 08-newsshIf you don’t enable public key authentication, VisualGDB will remember your password for this connection. The stored passwords are encrypted using a key stored in your Windows account. Thus, the password will only be available once you login using your Windows account.
  8. Once the connection has been made, press on ‘Finish’ in the wizard. 09-finish
  9. Build the project. VisualGDB will use the local toolchain to build it. 10a-build
  10. Set a breakpoint in the main function. Start debugging. VisualGDB will deploy your executable to the Raspberry PI board. 10-setbp
  11. The execution will pause at the breakpoint. 11-stoppedatbp
  12. If you want to add support for additional headers/libraries, copy them from Raspberry PI to the corresponding directory under <toolchain path>\arm-linux-gnueabihf\sysroot and update flags.mak to add new include directories and libraries.