{"id":7872,"date":"2022-06-09T09:59:09","date_gmt":"2022-06-09T16:59:09","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=7872"},"modified":"2022-06-09T09:59:09","modified_gmt":"2022-06-09T16:59:09","slug":"building-projects-with-toolchains-from-docker-containers","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/docker\/toolchains\/using\/","title":{"rendered":"Building Projects with Toolchains from Docker Containers"},"content":{"rendered":"<p>This tutorial shows how to build and debug a basic Raspberry Pi project using a toolchain running in a Docker container.<\/p>\n<p>Before you begin, follow <a href=\"https:\/\/visualgdb.com\/tutorials\/linux\/docker\/toolchains\/\">this tutorial<\/a> to create a container, configure it to run SSH server, and install the compatible toolchain inside it.<\/p>\n<ol>\n<li>Start Visual Studio and locate the VisualGDB Linux Project Wizard: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7873\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/01-newprj.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Specify the name and location for your project: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/02-name.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7874\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/02-name.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Proceed with creating a basic application using CMake. Other build systems (e.g. MSBuild or GNU Make) will work as well, although <a href=\"https:\/\/visualgdb.com\/documentation\/projects\/cmake\/\">Advanced CMake<\/a> provides better integration into Solution Explorer a few other features:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/03-type.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7875\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/03-type.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>The <strong>Linux Computer Selection<\/strong> page allows choosing the machine to run the build tools. However, if you just select the host running docker, VisualGDB would expect the tools to be installed directly on that host. Instead, click the &#8220;Create a new SSH connection&#8221; option to setup a connection to the container:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/new.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7883\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/new.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Configure the following settings for the new SSH connection:<br \/>\n<table style=\"border-collapse: collapse; width: 100%; height: 72px;\" border=\"1\">\n<tbody>\n<tr style=\"height: 24px;\">\n<td style=\"width: 33.3333%; height: 24px;\">Setting<\/td>\n<td style=\"width: 33.3333%; height: 24px;\">Value<\/td>\n<td style=\"width: 33.3333%; height: 24px;\">Example<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 33.3333%; height: 24px;\">Host name<\/td>\n<td style=\"width: 33.3333%; height: 24px;\">&lt;host name where Docker is running&gt;:&lt;redirected SSH port&gt;<\/td>\n<td style=\"width: 33.3333%; height: 24px;\">dockerhost:2222<\/td>\n<\/tr>\n<tr style=\"height: 24px;\">\n<td style=\"width: 33.3333%; height: 24px;\">User name<\/td>\n<td style=\"width: 33.3333%; height: 24px;\"><strong>root<\/strong> (as long as <strong>PermitRootLogin<\/strong> was enabled)<\/td>\n<td style=\"width: 33.3333%; height: 24px;\">root<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">Password<\/td>\n<td style=\"width: 33.3333%;\">Password set for the user by running &#8220;passwd&#8221; inside the container<\/td>\n<td style=\"width: 33.3333%;\">test<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/04-conn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7876\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/04-conn.png\" alt=\"\" width=\"586\" height=\"510\" \/><\/a><\/li>\n<li>Now we will select the toolchain that VisualGDB should use for building the projects. Open the toolchain dropdown and click &#8220;Specify toolchain manually&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/05-findgdb-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7884\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/05-findgdb-1.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>In this example, we are using the <strong>arm-linux-gnueabihf<\/strong> toolchain installed via a Debian package, and a separately installed <strong>gdb-multiarch<\/strong>. VisualGDB would normally expect gdb to be named and placed similarly to the other tools (e.g. gcc), so we can achieve this by creating a symbolic link. Run the following commands inside the container:\n<pre class=\"\">which arm-linux-gnueabihf-g++\r\nwhich gdb-multiarch<\/pre>\n<p>They will show the full path to the multiarch gdb (normally <strong>\/usr\/bin\/gdb-multiarch<\/strong>) and the ARM gcc (normally <strong>\/usr\/bin\/arm-linux-gnueabihf-g++<\/strong>). Replace &#8220;g++&#8221; with &#8220;gdb&#8221; in the gcc path and create a symbolic link there pointing to the original gdb-multiarch, e.g.:<\/p>\n<pre class=\"\">ln -s \/usr\/bin\/gdb-multiarch \/usr\/bin\/arm-linux-gnueabihf-gdb<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/link.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7885\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/link.png\" alt=\"\" width=\"1038\" height=\"354\" \/><\/a><\/li>\n<li>Now you point VisualGDB to the location of the created symlink:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/06-gdbexe.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7878\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/06-gdbexe.png\" alt=\"\" width=\"652\" height=\"359\" \/><\/a><\/li>\n<li>VisualGDB will automatically locate the other tools based on the name of the gdb executable, so you won&#8217;t need to configure them manually: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/07-configm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7879\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/07-configm.png\" alt=\"\" width=\"686\" height=\"452\" \/><\/a><\/li>\n<li>Enable the &#8220;Deploy the project to another Linux computer&#8221; checkbox and select the machine where you want to deploy the built executables:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/08-raspi-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7886\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/08-raspi-1.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>Once you click &#8220;Next&#8221;, VisualGDB will automatically verify the imported toolchain and will make sure it produces binaries that can run on the deployment target:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/check.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7887\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/check.png\" alt=\"\" width=\"470\" height=\"380\" \/><\/a>If the test fails, double-check that your toolchain is compatible with the target (i.e. comes from the same Linux distro, same version, and is intended for the same target).<\/li>\n<li>Finally, select where you would like to keep the source files. Advanced CMake projects allow keeping the entire source code directly on the target and accessing it via SSH, however, it may not be practical when using Docker containers, since the container contents gets reset each time it is re-created. Instead, we will select &#8220;Store sources on the Windows computer&#8221; and &#8220;Upload modified sources on each build&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/09-store.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7881\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/09-store.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a>You can also use the <a href=\"https:\/\/docs.docker.com\/storage\/bind-mounts\/\">&#8211;mount<\/a> parameter to mount a directory from the docker host directly inside the container, and keep the source code there.<\/li>\n<li>Press &#8220;Finish&#8221; to create the project. You will now be able to build and debug it as usual: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/10-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7882\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/10-debug.png\" alt=\"\" width=\"1216\" height=\"703\" \/><\/a><\/li>\n<li>If you have made any changes to the container in order to get VisualGDB working (e.g. symlinking <strong>gdb-multiarch<\/strong>), we advise committing them to the container image, so they won&#8217;t be lost next time you start the container, e.g.:\n<pre class=\"\">sudo docker stop raspibuild\r\nsudo docker commit raspibuild raspibuild-img\r\nsudo docker container prune -f\r\nsudo docker run -p 2222:22 -d --name raspibuild raspibuild-img<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/start-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7888\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2022\/06\/start-1.png\" alt=\"\" width=\"1105\" height=\"421\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to build and debug a basic Raspberry Pi project using a toolchain running in a Docker<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[72,111,33],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7872"}],"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=7872"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7872\/revisions"}],"predecessor-version":[{"id":7889,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/7872\/revisions\/7889"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=7872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=7872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=7872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}