{"id":1309,"date":"2016-01-19T16:18:08","date_gmt":"2016-01-20T00:18:08","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=1309"},"modified":"2016-01-19T16:41:24","modified_gmt":"2016-01-20T00:41:24","slug":"developing-linux-code-with-vagrant-vms-and-visualgdb","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/vagrant\/","title":{"rendered":"Developing Linux code with Vagrant VMs and VisualGDB"},"content":{"rendered":"<p>This tutorial shows how to use <a href=\"https:\/\/www.vagrantup.com\/\">Vagrant<\/a> to quickly setup virtual machines with popular Linux distros and use them to develop C\/C++ applications with Visual Studio. Before you begin, install VisualGDB 5.1 or later.<\/p>\n<ol>\n<li>Start Visual Studio and select &#8220;File-&gt;New-&gt; Project&#8221;. Then choose the VisualGDB Linux Project Wizard:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1310\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/01-newprj.png\" alt=\"01-newprj\" width=\"795\" height=\"444\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/01-newprj.png 795w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/01-newprj-300x168.png 300w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/a><\/li>\n<li>On the first page select &#8220;Create a new project -&gt; Application&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/02-app.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1311\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/02-app.png\" alt=\"02-app\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/02-app.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/02-app-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>On the next page simply select &#8220;Create a new Vagrant VM&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/03-vagrant1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1333\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/03-vagrant1.png\" alt=\"03-vagrant\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/03-vagrant1.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/03-vagrant1-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a>If you already have Vagrant VMs on this Windows machine, VisualGDB will detect them automatically by reading the <strong>%USERPROFILE%\\.vagrant.d\\data\\machine-index\\index<\/strong> file and show them in the list.<\/li>\n<li>If Vagrant is not installed, VisualGDB will show a dialog with the download link. Download it using the link from the window and click &#8220;locate Vagrant&#8221; to point VisualGDB at its install location:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/04-notfound.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1313\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/04-notfound.png\" alt=\"04-notfound\" width=\"565\" height=\"140\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/04-notfound.png 565w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/04-notfound-300x74.png 300w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/a><\/li>\n<li>Once VisualGDB knows where Vagrant is installed, it will allow choosing a box name and a destination folder. Click &#8220;Browse&#8221; to open the <a href=\"https:\/\/atlas.hashicorp.com\/boxes\/search\">public Vagrant box catalog<\/a>:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/05-boxname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1314\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/05-boxname.png\" alt=\"05-boxname\" width=\"565\" height=\"140\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/05-boxname.png 565w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/05-boxname-300x74.png 300w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/a><\/li>\n<li>Find a box with the distro you want to try out (in this example we will use Ubuntu Vivid) and click on it:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/06-centos.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1315\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/06-centos.png\" alt=\"06-centos\" width=\"936\" height=\"691\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/06-centos.png 936w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/06-centos-300x221.png 300w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/li>\n<li>VisualGDB will automatically paste the box name into the &#8220;Vagrant box&#8221; field. You can also enter a box URL (e.g. from <a href=\"http:\/\/www.vagrantbox.es\/\">this page<\/a>) to get a third-party box. Specify the destination folder where Vagrant will store the VM configuration files:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/07-filled.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1316\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/07-filled.png\" alt=\"07-filled\" width=\"565\" height=\"140\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/07-filled.png 565w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/07-filled-300x74.png 300w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/a><\/li>\n<li>Click &#8220;OK&#8221;. VisualGDB will begin creating the box. If you don&#8217;t have VirtualBox installed, Vagrant will install it automatically:\u00a0 <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/08-vbox.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1317\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/08-vbox.png\" alt=\"08-vbox\" width=\"670\" height=\"375\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/08-vbox.png 670w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/08-vbox-300x168.png 300w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/a><\/li>\n<li>Once the installation is complete, Vagrant will download and start the VM:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/09-inst.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1318\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/09-inst.png\" alt=\"09-inst\" width=\"670\" height=\"375\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/09-inst.png 670w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/09-inst-300x168.png 300w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/a><\/li>\n<li>Once the VM is running, VisualGDB will show it in the &#8220;Remote computer&#8221; field just like a normal SSH connection. You can click the console button to the right of it to connect to the box via SSH if you want to experiment with it on your own:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/10-selected.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1319\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/10-selected.png\" alt=\"10-selected\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/10-selected.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/10-selected-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>VisualGDB will open another window where you can try running various commands on the machine:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/11-ssh.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1320\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/11-ssh.png\" alt=\"11-ssh\" width=\"1019\" height=\"475\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/11-ssh.png 1019w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/11-ssh-300x140.png 300w\" sizes=\"(max-width: 1019px) 100vw, 1019px\" \/><\/a><\/li>\n<li>Press &#8220;Next&#8221; in the wizard. If your Vagrant box does not come with GCC, GDB or Make, VisualGDB will detect this and prompt to install the missing packages. Simply click &#8220;Yes&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/12-pkgs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1321\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/12-pkgs.png\" alt=\"12-pkgs\" width=\"445\" height=\"193\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/12-pkgs.png 445w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/12-pkgs-300x130.png 300w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/a><\/li>\n<li>The installation process will take some time, but should ultimately succeed unless your VM is based on an old distro for which the repositories are not maintained. Most recent Debian- and RedHat-based distros should be supported automatically:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/13-getgcc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1322\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/13-getgcc.png\" alt=\"13-getgcc\" width=\"736\" height=\"547\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/13-getgcc.png 736w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/13-getgcc-300x223.png 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/a><\/li>\n<li>The next page allows specifying where VisualGDB will store the files on the Vagrant VM. In this wizard we will proceed with the default settings:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/14-sources.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1323\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/14-sources.png\" alt=\"14-sources\" width=\"825\" height=\"641\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/14-sources.png 825w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/14-sources-300x233.png 300w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221;. VisualGDB will generate the project for you. Build it by pressing Ctrl-Shift-B:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/15-hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1324\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/15-hello.png\" alt=\"15-hello\" width=\"1005\" height=\"676\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/15-hello.png 1005w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/15-hello-300x202.png 300w\" sizes=\"(max-width: 1005px) 100vw, 1005px\" \/><\/a><\/li>\n<li>You can modify the source code to call the gethostname() function to display the host name where the test program is running. Then set a breakpoint somewhere in the code and hit F5 to begin debugging:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/16-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1325\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/16-bkpt.png\" alt=\"16-bkpt\" width=\"1007\" height=\"678\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/16-bkpt.png 1007w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/16-bkpt-300x202.png 300w\" sizes=\"(max-width: 1007px) 100vw, 1007px\" \/><\/a><\/li>\n<li>You can always see the state of the current Vagrant virtual machines via Tools-&gt;SSH Host Manager. Select the newly created VM and press &#8220;Stop VM&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/17-vmlist.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1326\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/17-vmlist.png\" alt=\"17-vmlist\" width=\"712\" height=\"422\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/17-vmlist.png 712w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/17-vmlist-300x178.png 300w\" sizes=\"(max-width: 712px) 100vw, 712px\" \/><\/a><\/li>\n<li>VisualGDB will invoke the &#8220;vagrant halt&#8221; command that gracefully stops the virtual machine:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/18-stopping.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1327\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/18-stopping.png\" alt=\"18-stopping\" width=\"670\" height=\"359\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/18-stopping.png 670w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/18-stopping-300x161.png 300w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/a><\/li>\n<li>Next time you want to debug the project, VisualGDB will automatically detect if the VM is not running and will seamlessly launch it and establish a new connection so that you can continue debugging your code:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/19-boot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1328\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/19-boot.png\" alt=\"19-boot\" width=\"1007\" height=\"678\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/19-boot.png 1007w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2016\/01\/19-boot-300x202.png 300w\" sizes=\"(max-width: 1007px) 100vw, 1007px\" \/><\/a>Do not forget to build your code again if you have stopped the VM, as the \/tmp directory used to store the uploaded sources is deleted each time the VM restarts. You can also use a different directory to store your files (e.g. inside the home directory of the current user).<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use Vagrant to quickly setup virtual machines with popular Linux distros and use them to<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[33,113,112],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/1309"}],"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=1309"}],"version-history":[{"count":5,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/1309\/revisions"}],"predecessor-version":[{"id":1334,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/1309\/revisions\/1334"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=1309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=1309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=1309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}