Developing a Raspberry PI app with Visual Studio
This tutorial demonstrates how to build and debug a simple Raspberry PI application using Visual Studio.
- If you have not prepared your SD card yet, download WinFLASHTool and use it to write the image to the SD card:
- Start your Raspberry PI and connect a network cable to it.
- Please download and install the latest VisualGDB.
- On your Windows machine start Visual Studio, select "File->New project". Then select "VisualGDB->Linux Project Wizard". Specify project location and press "OK".
- The VisualGDB Linux Project Wizard will start. As we are making a simple "Hello, World" application, keep "Create a new project" selected and press "Next".
- If you have not created any Raspberry PI projects before, select "Create a new SSH connection" on the next page.
- Provide the IP address of your Raspbery PI box, the user name ("pi" by default) and password ("raspberry" by default). 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. If 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.
- You could use 2 options to build your first Raspberry PI
app: build it on Windows with a cross-compiler or build it
on the Raspberry PI itself. The first option is faster,
while the second is easier to setup. In this tutorial we
will use the second option:
Use the diagram at the bottom of the
page to check the correctness of your setup:
- The hammer icon corresponds to the machine where the compiler is run.
- The "play" icon corresponds to the machine where the debugged program is launched.
- When you press "Next", VisualGDB will test your toolchain by trying to compile and run a trivial program. If any errors are detected at this stage, you will see a detailed error log with further troubleshooting information.
- As the same source code will be edited under Windows and then compiled under Linux, VisualGDB will need to keep the sources synchronized. The easiest way is to use automatic file uploading via SSH.
- Press Finish to complete the wizard. If this is your first project for Raspberry PI, VisualGDB will cache the include directories to make them available through IntelliSense.
- Replace the contents of the main source file with the
using namespace std;
int main(int argc, char *argv)
printf("The host name is %s\n", szHost);
- Build the solution. You will see how the source files are transferred to Raspberry PI and compiled there:
- Set a breakpoint on the printf() line and press F5 to start debugging. The breakpoint will trigger:
- You can now use all normal Visual Studio techniques to debug your app. Feel free to look through our generic Linux tutorial for more hints and clues.
|Follow @sysprogs Tweet|