Developing Remote Linux Projects with VisualGDB and VirtualBox

This tutorial shows how to use VisualGDB to develop and debug C/C++ code on Linux virtual machines running on VirtualBox. We will show how to create a virtual machine, configure the network settings and setup VisualGDB to access it. Before you begin, download and install VirtualBox, Visual Studio and VisualGDB. Also choose a Linux distro you want to install on the VirtualBox and download an ISO image of the install DVD. If you are unfamiliar with Linux distros, we recommend using a 64-bit Kubuntu.

  1. First we will show how to create a new Linux Virtual Machine. Start VirtualBox and click “New” to create a new Virtual Machine:01-vbox
  2. Enter the name for the VM, set the type to “Linux” and the version according to the distro you are going to use:02-name
  3. On the next page select the memory size you want to allocate for your VM:03-memory
  4. Select “Create a virtual hard disk now”:04-disk
  5. Proceed with the default “VDI” disk format:05-type
  6. Select “Dynamically allocated” and click “Next”:06-dyn
  7. Set the disk size based on the amount of applications and data you want to have on the VM:07-loc
  8. Press “Create” to create the new virtual machine. Once it is created, click on “Start”:08-settings
  9. VirtualBox will ask for the start-up disk that will install Linux on your virtual machine. Select the ISO image with the Linux installer you have previously downloaded and click “Start”:09-startupThe virtual machine will boot from the installer ISO. The next steps of this tutorial will be specific to Kubuntu and might slightly vary if you are using a different Linux distro.
  10. Double-click on the “Install Kubuntu” shortcut:10-inst
  11. The Kubuntu installation wizard will start. Select your language on the first page and click “Continue”:11-welcome
  12. We recommend keeping the default settings on the next page. Click “Continue” to proceed:12-prepare
  13. Select “Guided – use entire disk” and click “Install Now”:14-disk
  14. Select your time zone and click “Continue”:15-time
  15. On the next page confirm your keyboard layout:16-keyboard
  16. Finally set your user name, password and a machine name. The machine name specified here will be reported to your DHCP server and hence can be used to find the machine from VisualGDB if your DHCP server is configure to create a DNS record for it:17-settings
  17. Wait for the installation to complete:18-progress
  18. Once Kubuntu is installed, click “Restart now”:19-restartThe VM will now restart and boot into the newly created Linux installation. Now we will show how to configure the network settings so that you can access your virtual machine remotely.
  19. Open a terminal on your VM and run “ifconfig” if it’s not installed, run the following command to install it:
    sudo apt-get install net-tools

    20-ifconfig

  20. Ifconfig will display the current IP address of the VM, however in the default configuration this address won’t be reachable from your Windows machine:21-ipaddr
  21. Open the VM settings and switch the network to “Bridged”. Ensure that the underlying adapter corresponds to your physical network adapter:22-bridged
  22. Ensure your network has a functioning DHCP server and run “sudo dhclient -v” to acquire an IP address for the VM:23-dhcpIf you don’t have a DHCP server, you would need to configure the IP address manually and ensure it doesn’t conflict with any other machines on your network.
  23. In order to access the Linux machine over network, install the OpenSSH Server package by running the following command:
    sudo apt-get install openssh-server

    24-openssh

  24. Try pinging the VM from the Windows machine using the name specified during Linux installation (not the name entered when creating the VM in VirtualBox):ipaddrIf it doesn’t work, try using the IP address shown by dhclient instead. If this doesn’t work either, double-check that the VM is attached to the correct network adapter.
  25. Now you are ready to create your first C/C++ project for this machine with VisualGDB. Start Visual Studio and launch the VisualGDB Linux Project Wizard:25-newprj
  26. Proceed with the default MSBuild subsystem:26-app
  27. On the next page click “Create a new SSH connection”:27-newssh
  28. Enter the host name (verified by pinging it) and the user name/password: 28-newconn
  29. Click “Create” to begin connecting. VisualGDB will ask whether you want to save the host key. Confirm it by pressing “Save”:29-savekey
  30. Once the VM is selected in the wizard, click “Next”:30-next
  31. VisualGDB will check the VM for the packages required to create your project and suggest installing them automatically. Click “yes”:31-gcc
  32. Proceed with the default settings for storing the source files and click “Finish” to create your project:32-files
  33. Try building the project with Ctrl-Shift-B:33-build
  34. Set a breakpoint in the function outputting the “Hello, World” line and press F5 to start debugging:34-debug
  35. You can customize various advanced settings for your project by right-clicking on it in Solution Explorer and selecting “VisualGDB Project Properties”:35-props