Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote development of Visual C++ applications from Linux

Remote development on Linux from Windows is easily doable via SSH.

However, what about the other way? I need to build and debug my Visual C++ application on Windows, but I want to work on a Linux system.

  1. Cross-compiling via MinGW doesn't work because of MSVC-specific libraries
  2. Ubuntu on Windows is a good start, but I'd like to work on a real Linux system
  3. RDP/VNC or something like that doesn't help either, because than I'd work on Windows again
  4. So does a virtual machine

Maybe something like Powershell on Linux + SSH to the Windows Powershell?

like image 558
Julius Bullinger Avatar asked Sep 29 '17 09:09

Julius Bullinger


People also ask

Can visual studios run on Linux?

For its part, Microsoft documentation says: "Visual Studio 2022 enables you to build and debug apps for Linux using C++, Python, and Node.

Can Visual Studio cross compile Linux?

Visual Studio C and C++ development isn't just for Windows anymore. This tutorial shows how to use Visual Studio for C++ cross platform development on Windows and Linux. It's based on CMake, so you don't have to create or generate Visual Studio projects. When you open a folder that contains a CMakeLists.

Can Visual C++ run on Linux?

It's found at the top of the table of contents on this page. You can use the Visual Studio IDE on Windows to create, edit, and debug C++ projects that execute on a remote Linux system, virtual machine, or the Windows Subsystem for Linux.


1 Answers

I regularly develop Visual C# applications remotely from Linux, not MSVC for the most part, but, like you, I wanted to find a way to build and debug Windows-targeted applications and libraries on remote Windows machines without working directly in the box using RDP, Visual Studio, etc.

It's difficult to answer this question without more information about the development and debugging tools you prefer to use on Linux for the types of applications you develop. I'll try to provide a general overview and update the answer for details you add about your workflow.

Cygwin, similar to MinGW's MSYS, provides a Unix-like environment for Windows. Most importantly, Cygwin, unlike MinGW/MSYS, includes an implementation of the OpenSSH server that enables us to connect to the Windows box over SSH from Linux (or any other device with an SSH client, really). We can install the sshd package using Cygwin's setup utility. After connecting, Cygwin drops us into a Bash shell by default. With this capability, we can:

  • Execute remote commands and scripts over SSH.
  • Edit files using our favorite *nix command-line text editor (Vim, Emacs, etc.)
  • Mount remote filesystems locally using SSHFS (if Windows shares are unavailable).
  • Forward or tunnel ports if needed.

The availability of a general-purpose shell makes almost anything possible. We can execute batch files, PowerShell scripts, and native Windows executables from Cygwin's shell environment in addition to Linux scripts and Cygwin programs.

For example, we could run msbuild from the SSH session command line to build our VC++ application or we could configure our local GUI editor or IDE running in Linux to execute msbuild over SSH when we click the "build" button.

We could set up a similar environment in recent versions of Windows using the Windows Subsystem for Linux ("WSL", Bash on Windows). I personally prefer Cygwin for greater portability and ease of configuration. Cygwin's sshd can run as a Windows service, and, as an established project, Cygwin integrates very well with Windows systems (user accounts, filesystems, Windows APIs, etc.).

Working with Code

We can choose from several workflows depending on our tools and comfort-level with the command-line:

  1. Completely text-based—all work performed through the SSH session
  2. Use local tools on files mounted in a remote filesystem
  3. Use local tools and synchronize files

I use the first approach. I'm a heavy Vim user, so I connect to Windows machines over SSH to do my work on the command-line using the tools and environment provided by Cygwin. The availability of tools typically found on Linux simplifies many tasks that are hard to do from the default Windows console. We can write shell scripts to automate tasks that Visual Studio might normally do for us. For example, I wrote a wrapper script around mstest that reads the XML test results and outputs them in a format that's easy to read in a terminal.

If we prefer to use a GUI editor or IDE, we can mount the remote code locally so tools can read and write files as if they were part of the Linux machine's local filesystem. We likely still need to use SSH to execute commands needed to build the projects, but many editors allow us to configure this command as the project's "build" action.

Sometimes a remote filesystem is too slow for effective editing. In these cases, we can synchronize files between the Linux development machine and the Windows host using a tool like rsync or the editor's "upload on save" feature (over SFTP, for example), if available.

Debugging

Everything works pretty well until we try to find a way to debug our applications. As of now, there is no reasonable substitute for Visual Studio's debugger when working with Visual C++ projects. We can debug managed C# applications running on the CLR using MDbg, but no comparable tool exists for C++ programs.

We can try to use gdb (from MinGW, Cygwin, etc.) for basic, low-level debugging of native binaries, like reading memory addresses, but the debugger does not yet support reading Microsoft's debugging symbols, so the debugging experience is very limited. Microsoft began documenting the PDB format a couple years ago, so we may see some compatibility in the future. Even so, it will take a long time to produce a satisfactory alternative to Visual Studio's excellent debugging tools.

For debugging, RDP is currently our best—and probably, only—option. For a more native-feeling experience, we can run Visual Studio using rdesktop (or other RDP client) and seamlessrdp to create a single-window RDP session of the Visual Studio IDE instead of a full desktop which integrates with whatever window manager we're using on Linux.

Sometimes we can get around launching a full Visual Studio debugging session for simple debugging scenarios by adding tracing to our application that outputs values to the console or to a log file. In many cases, this is faster than starting the debugger anyway.

We can also try to use Eclipse's CDT debugger configured for the Visual C++ toolchain. This may enable us to perform remote debugging using an Eclipse instance on the Linux machine. I have never tried this approach, and I expect there may be some issues when the application is linked against Microsoft's libraries.

like image 101
Cy Rossignol Avatar answered Oct 20 '22 06:10

Cy Rossignol