This post describes how to create a project on a remote Linux and also Windows subsystem for Linux , build it remotely and also debug it from Visual Studio step by step.
I previously used Netbeans to debug Linux C++ applications via remote SSH and GDB from Windows :
However I find VisualStudio setup is easier and more convenient to use.
Linux side :
The only setup you need in your Linux is an SSH server. You can either use password based authentication or public key based authentication from Visual Studio. See section 4 of previous blog post for an example setup on Debian :
It is written for Debian , however it is mostly same in other distributions. In case you want to use Windows Subsystem for Linux in your Windows10 or directly an Ubuntu ( jump to step C ) :
a) Install WSL , either Ubuntu or OpenSuse following this document : https://docs.microsoft.com/en-us/windows/wsl/install-win10
b) After installation , you will have to create an account with password authenticaton. Go to default Windows command prompt and type :
Then specify a username and password.
c) You will want to install g++, gdb and SSH :
sudo apt-get update
sudo apt install -y build-essential
sudo apt install -y gdb
sudo apt install -y openssh-server
sudo service ssh –full-restart
CentOS : The main Linux distro I use is Centos 7. I had to update my existing openSSH daemon and restart it at least once to connect to it from Visual Studio :
yum install openssh openssh-server openssh-clients openssl-libsyum install openssh openssh-server openssh-clients openssl-libs systemctl restart sshd.service
Visual Studio side :
You can use either Visual Studio 2015 Community Edition and Visual C++ for Linux extension here : https://www.gallery.expression.microsoft.com/725025cf-7067-45c2-8d01-1e0fd359ae6e
However I would suggest using Visual Studio 2017 community edition for a few reasons :
a) You don`t even need an extension . Remote Linux setup comes with VS2017.
b) Whenever I debugged a remote Linux project with VS2015, the debugger will stop in certain unhandled Linux signals. Unfortunately I could not find a way of surpressing those. However you won`t have this issue with VS2017.
You can download VS2017 community edition from here : https://www.visualstudio.com/vs/cplusplus/
1 . You have to choose “Makefile project ( Linux ) ” in VisualStudio 2017 in order to use an existing project :
2. You will have to add all files to your VS solution. You can either add the existing files from remote if Linux server has Samba . In case you can`t do that you can also copy the project to your Windows system and add all files to your solution :
3. Go to your project`s settings and choose “Remote build”. You will need to specify the remote build command. That command will be running in home directory of your SSH connection. An example :
4. Go to your project`s settings and choose Debugging tab. Here you need to specify the binary output to debug for GDB. Paths you enter will be relative to the home directory of your SSH account :
Note that you can either use “gdb” which will be driving gdb via SSH or “gdbserver” . Just “gdb” is the method I use in this post. However if you want to run gdbserver ( it is independent from GDB ) in remote Linux whereas you are unable to install GDB, you can also use “gdbserver” mode 6o connect to GDBserver running in your remote Linux.
5. An extra step at this point is setting your include path. That is extremely useful as you can feed VisualStudio`s s intelliSense and navigate native Linux headers. For simplicity , I copied my Linux` /usr/include directory to my local Windows and specified that path as one of include path in the project settings :
6. Finally , the last step is connecting to your Linux server. When you press debug button for the first time , you can connect using the connection screen :
And finally this is how it looks :
7. Linux console interaction : If you go to Debug -> Linux console , it will bring up Linux console window that you can interact with :
What about Visual Studio code :
Visual Studio Code is a great lightweight development environment that you can use for almost anything. I tried using from Windows targeting a remote Linux that runs gdbserver however couldn`t get it working. My current understanding is that it is not currently supporting remote GDB sessions from Windows to Linux server , however you can still connect to remote Linux/MacOSx servers from Linux/MacOSx clients as described here :