Porting Windows projects to Linux with Windows 10 Linux Subsystem

This tutorial shows how to port native Win32 projects to Linux using VisualGDB and the Windows 10 Linux Subsystem. Before you begin, install Windows 10, Visual Studio and VisualGDB 5.3 or later.

  1. Open Visual Studio and create a regular Win32 Console application:01-winprj
  2. Open the stdafx.h file and remove references to tchar.h and targetver.h that are not available on Linux:02-stdafx
  3. Modify the main() function to print a basic “Hello, world” message and build the project:03-hello
  4. Set a breakpoint on the printf() line and begin debugging with F5 to ensure that the native Windows build runs:04-debug
  5. Now we will show how to target the Windows 10 Linux subsystem. Unlike a separate virtual machine running Linux that would require synchronizing files over network, the Windows 10 Linux Subsystem can access the Windows filesystem directly, making the setup much easier. Before you begin, ensure that the Linux Subsystem is installed via Add/Remove Programs -> Turn Windows features on or off:05-wsl
  6. Go back to Visual Studio and select Project->Add VisualGDB Configuration->New Linux Configuration:06-addlinux
  7. VisualGDB will show the New Linux Configuration wizard. In this tutorial we will use MSBuild to build the project, so proceed with the default settings:07-msbuild
  8. On the next page select “Use the Windows 10 Linux Subsystem” and proceed with the default toolchain:08-lxss
  9. VisualGDB will automatically detect the path mappings between the Windows and Linux subsystems, so simply click “Finish” on the last page:09-map
  10. VisualGDB will create a new solution platform called ‘VisualGDB’ and will insert the new configuration there. Ensure that you can build the project by pressing Ctrl-Shift-B:10-build
  11. Set a breakpoint in main() and start debugging by pressing F5:11-main
  12. Include the <unistd.h> file from the main source file and select the corresponding line. See how VisualGDB automatically discovered the file under the lxss root file system. You can press the “Go” button to open the file, or simply begin using any functions declared in it and IntelliSense will automatically recognize them:12-unistd
  13. If you add new libraries to your Linux Subsystem via apt-get, VisualGDB will automatically locate the header files installed by them (as long as the corresponding include directories are set in the project properties), so you won’t need to re-synchronize them. You can get a quick overview of the directories seen by VisualGDB via VisualGDB Project Properties -> IntelliSense Directories:13-includedirs
  14. As long as you are using MSBuild, you can use the regular Visual Studio project properties to set various build-related settings:14-precomp
  15. For common settings like Include Paths we recommend using VisualGDB Project Properties instead. This will refer to the same settings, but will provide more convenient GUI for editing them:15-inc