{"id":80,"date":"2023-09-04T18:00:26","date_gmt":"2023-09-05T01:00:26","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=80"},"modified":"2023-09-05T09:48:23","modified_gmt":"2023-09-05T16:48:23","slug":"raspberry","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/raspberry\/","title":{"rendered":"Developing a Raspberry PI app with Visual Studio"},"content":{"rendered":"<p>This tutorial demonstrates how to build and debug a simple <a href=\"http:\/\/www.raspberrypi.org\/\">Raspberry PI<\/a> application using Visual Studio. The same steps will also work with Raspberry Pi 2.<\/p>\n<ol>\n<li>If you have not prepared your SD card yet, download and start the <a href=\"https:\/\/www.raspberrypi.com\/software\/\">Raspberry Pi Imager<\/a>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/imager.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8261\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/imager.png\" alt=\"\" width=\"682\" height=\"452\" \/><\/a><\/li>\n<li>Select a Raspberry Pi OS version to program and take a note of the exact release date:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/version.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8262\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/version.png\" alt=\"\" width=\"682\" height=\"452\" \/><\/a><\/li>\n<li>Use the Settings button to enable SSH on the programmed image, and provide the user name\/password you would like to use:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/ssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8263\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/ssh.png\" alt=\"\" width=\"682\" height=\"452\" \/><\/a><\/li>\n<li>Start your Raspberry PI and connect a network cable to it.<\/li>\n<li>Download and install Visual Studio and <a href=\"\/download\">the latest VisualGDB release<\/a>.<\/li>\n<li>On your Windows machine start Visual Studio, select &#8220;File-&gt;New project&#8221;. Then select locate the VisualGDB Linux Project Wizard and press &#8220;Next&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/01-linuxp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8264\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/01-linuxp.png\" alt=\"\" width=\"1014\" height=\"675\" \/><\/a><\/li>\n<li>Enter the name and location of the project you are creating and click &#8220;Create&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/02-name.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8265\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/02-name.png\" alt=\"\" width=\"1014\" height=\"675\" \/><\/a><\/li>\n<li>The VisualGDB Linux Project Wizard will start. As we are making a simple &#8220;Hello, World&#8221; application, keep &#8220;Create a new project&#8221; selected and press &#8220;Next&#8221;. <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/03-app.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8266\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/03-app.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a>If you are familiar with the classical Visual Studio projects, we advise selecting the MSBuild system. Otherwise, consider using <a href=\"https:\/\/visualgdb.com\/documentation\/projects\/cmake\/\">Advanced CMake<\/a>.<\/li>\n<li>If you have not created any Raspberry PI projects before, select &#8220;Create a new SSH connection&#8221; on the next page:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/04-newconn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8267\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/04-newconn.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Provide the host name or IP address of your Raspbery PI box, and the user name\/password selected in the Raspberry Pi imager. It is recommended to check the &#8220;setup public key&#8221; checkbox, so that VisualGDB will automatically generate an public\/private keypair, store it in your Windows account&#8217;s key container and setup the Raspberry PI box to use it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/05-pass.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8268\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/05-pass.png\" alt=\"\" width=\"586\" height=\"510\" \/><\/a><span class=\"warning\">If you don&#8217;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.<\/span><\/li>\n<li>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: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/06-gotconn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8269\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/06-gotconn.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a>Use the diagram at the bottom of the page to check the correctness of your setup:\n<ul>\n<li>\u00a0The hammer icon corresponds to the machine<br \/>\nwhere the compiler is run.<\/li>\n<li>The &#8220;play&#8221; icon corresponds to the machine where the debugged program is launched.<\/li>\n<\/ul>\n<\/li>\n<li>When you press &#8220;Next&#8221;, 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. <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/07-test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8270\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/07-test.png\" alt=\"\" width=\"470\" height=\"380\" \/><\/a><\/li>\n<li>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:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/08-upload.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8271\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/08-upload.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>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.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/09-dirs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8272\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/09-dirs.png\" alt=\"\" width=\"470\" height=\"220\" \/><\/a><\/li>\n<li>Replace the contents of the main source file with the following:\n<pre class=\"\">#include &lt;stdio.h&gt;\r\n#include &lt;unistd.h&gt;\r\n\r\nint main(int argc, char *argv[])\r\n{\r\n    char szHost[128];\r\n    gethostname(szHost, sizeof(szHost));\r\n    printf(\"The host name is %s\\n\", szHost);\r\n    return 0;\r\n}<\/pre>\n<\/li>\n<li>Build the solution. You will see how the source files are transferred to Raspberry PI and compiled there:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/10-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8273\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/10-build.png\" alt=\"\" width=\"1062\" height=\"723\" \/><\/a><\/li>\n<li>Set a breakpoint on the printf() line and press F5 to start debugging. The breakpoint will trigger:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/11-host.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8274\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/11-host.png\" alt=\"\" width=\"1062\" height=\"723\" \/><\/a><\/li>\n<li>VisualGDB provides an advanced Clang-based IntelliSense engine that is fully compatible with GNU language extensions and provides advanced features like refactoring, Code Map and auto completion in the Watch windows. E.g. you can click the link above &#8220;main&#8221; to quickly visualize the calls from and to this function:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/12-codejumps.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8276\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/12-codejumps.png\" alt=\"\" width=\"1062\" height=\"723\" \/><\/a><\/li>\n<li>You can customize various project settings by right-clicking on the project in Solution Explorer and selecting VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/13-props.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8277\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/03\/13-props.png\" alt=\"\" width=\"1067\" height=\"749\" \/><\/a><\/li>\n<li>You can now use all normal Visual Studio techniques to debug your app. If you want more examples, check out the following tutorials:\n<ul>\n<li><a href=\"http:\/\/visualgdb.com\/tutorials\/raspberry\/crosscompiler\/\">Using cross-compiler to build Raspberry PI apps<\/a><\/li>\n<li><a href=\"https:\/\/visualgdb.com\/tutorials\/linux\/qt\/cmake\/\">Cross-compiling QT apps for Raspberry PI<\/a><\/li>\n<li><span class=\"auto-style3\"><a href=\"\/tutorials\/linux\/\">Creating Linux apps with Visual Studio<\/a><\/span><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>If you want to develop a kernel module for Raspberry PI an debug it over JTAG, follow <a href=\"http:\/\/visualkernel.com\/tutorials\/raspberry\/basicmodule\/\"> this tutorial<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial demonstrates how to build and debug a simple Raspberry PI application using Visual Studio. The same steps will<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[33,85],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/80"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":8,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":8300,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/80\/revisions\/8300"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}