{"id":165,"date":"2018-05-31T12:39:31","date_gmt":"2018-05-31T19:39:31","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=165"},"modified":"2023-09-08T08:56:39","modified_gmt":"2023-09-08T15:56:39","slug":"raspberry-crosscompiler","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/raspberry\/crosscompiler\/","title":{"rendered":"Using a Cross-compiler for Raspberry PI"},"content":{"rendered":"<p>This tutorial shows how to develop for Raspberry PI using a cross compiler in Visual Studio.<\/p>\n<p>Before we begin, ensure that <a href=\"\/download\">VisualGDB<\/a>\u00a0is installed.<\/p>\n<ol>\n<li>Start Visual Studio. Go to File-&gt;New-&gt;Project and select VisualGDB-&gt;Linux Project Wizard. Choose a name and location for the project and press &#8216;OK&#8217; when done.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4030\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj.png\" alt=\"01-prj\" width=\"941\" height=\"653\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/01-prj-130x90.png 130w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>Choose &#8216;<strong>Create a new project<\/strong>&#8216; -&gt; &#8216;<strong>Application<\/strong>&#8216;. If you are familiar with the classic Visual Studio C++ projects, select &#8216;<strong>MSBuild<\/strong>&#8216;. Otherwise, choose &#8216;<strong>CMake<\/strong>&#8216; and press &#8216;Next&#8217;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjtype.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4031\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjtype.png\" alt=\"02-prjtype\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjtype.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/02-prjtype-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Choose &#8216;Build the project locally with a cross-compiler, then open the cross-toolchain selector and click &#8220;Download more toolchains&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-getmore.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4033\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-getmore.png\" alt=\"03-getmore\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-getmore.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/03-getmore-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Choose the toolchain to be downloaded and installed.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/raspitc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4042\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/raspitc.png\" alt=\"raspitc\" width=\"710\" height=\"378\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/raspitc.png 710w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/raspitc-300x160.png 300w\" sizes=\"(max-width: 710px) 100vw, 710px\" \/><\/a><\/li>\n<li>Specify the installation directory. For the best compatibility with GDB and Make, it is recommended to avoid paths with spaces when installing toolchains:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/raspberry\/crosscompiler\/05-toolchaininstall.png\"><br \/>\n<\/a><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/04-getraspi.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4034\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/04-getraspi.png\" alt=\"04-getraspi\" width=\"586\" height=\"139\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/04-getraspi.png 586w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/04-getraspi-300x71.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/a><\/li>\n<li>VisualGDB will automatically\u00a0download and install the toolchain:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/05-download.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4035\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/05-download.png\" alt=\"05-download\" width=\"470\" height=\"203\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/05-download.png 470w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/05-download-300x130.png 300w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/a><\/li>\n<li>Once the installation of the toolchain completes, the installed toolchain will\u00a0appear in the toolchain selector.\u00a0If you are using VisualGDB 5.4 or later with the latest Raspberry Pi toolchain, you can click on the SD card\u00a0icon to the right from the\u00a0toolchain\u00a0selector to download the compatible SD card image from the Raspberry Pi website automatically:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/sd1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4050\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/sd1.png\" alt=\"sd\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/sd1.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/sd1-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Ensure your Raspberry Pi is running from the correct SD card image and that it&#8217;s connected to your network. Now we will configure VisualGDB to target it by\u00a0creating\u00a0a new SSH connection for it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/newconn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4051\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/newconn.png\" alt=\"newconn\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/newconn.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/newconn-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Choose the hostname or ip of the board together with the user name and password. Here we use the default user name <strong>pi<\/strong> and password <strong>raspberry<\/strong>. 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. Press on &#8216;Create&#8217; to make the connection.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-sshdetails.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4037\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-sshdetails.png\" alt=\"07-sshdetails\" width=\"586\" height=\"485\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-sshdetails.png 586w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/07-sshdetails-300x248.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/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>Once the connection has been made, press on &#8216;Finish&#8217; in the wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/finish.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4052\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/finish.png\" alt=\"finish\" width=\"886\" height=\"693\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/finish.png 886w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2018\/05\/finish-300x235.png 300w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/a><\/li>\n<li>Build the project. VisualGDB will use the local toolchain to build it.<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/09-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4039\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/09-project.png\" alt=\"09-project\" width=\"1128\" height=\"726\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/09-project.png 1128w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/09-project-300x193.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/09-project-1024x659.png 1024w\" sizes=\"(max-width: 1128px) 100vw, 1128px\" \/><\/a><\/li>\n<li>Set a breakpoint in the main function. Start debugging. VisualGDB will deploy your executable to the Raspberry PI board and the breakpoint will hit:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/10-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4040\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/10-debug.png\" alt=\"10-debug\" width=\"1128\" height=\"726\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/10-debug.png 1128w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/10-debug-300x193.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/10-debug-1024x659.png 1024w\" sizes=\"(max-width: 1128px) 100vw, 1128px\" \/><\/a>You can use the regular Visual Studio project properties to\u00a0change various parameters (e.g.\u00a0include directories or preprocessor macros). For advanced settings, such as unit tests, dynamic program analysis,\u00a0profiling, etc.\u00a0use the VisualGDB Project Properties window.<\/li>\n<li>If you want to add support for additional headers\/libraries,\u00a0install them on Raspberry Pi via <strong>apt-get<\/strong> and then open VisualGDB Project Properties on the Build Settings page and click &#8220;Synchronize sysroot&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/11-resync.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4041\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/11-resync.png\" alt=\"11-resync\" width=\"1128\" height=\"726\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/11-resync.png 1128w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/11-resync-300x193.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/11-resync-1024x659.png 1024w\" sizes=\"(max-width: 1128px) 100vw, 1128px\" \/><\/a><\/li>\n<li>Proceed with the suggested directory list and VisualGDB will automatically ensure that all the libraries installed on Raspberry Pi become\u00a0available when using the cross-toolchain:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/12-confirm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4044\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/12-confirm.png\" alt=\"12-confirm\" width=\"406\" height=\"354\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/12-confirm.png 406w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2014\/02\/12-confirm-300x262.png 300w\" sizes=\"(max-width: 406px) 100vw, 406px\" \/><\/a><\/li>\n<\/ol>\n<p>If you\u00a0would like to use CMake instead of MSBuild, try out the <a href=\"https:\/\/visualgdb.com\/tutorials\/raspberry\/cmake\/\">Advanced CMake Project Subsystem<\/a> that\u00a0lets you conveniently use the Visual Studio GUI for managing CMake projects.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to develop for Raspberry PI using a cross compiler in Visual Studio. Before we begin, ensure<\/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":[72,33,85],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/165"}],"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=165"}],"version-history":[{"count":6,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":8319,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/165\/revisions\/8319"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}