{"id":3292,"date":"2017-10-11T16:07:27","date_gmt":"2017-10-11T23:07:27","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=3292"},"modified":"2017-10-11T16:07:27","modified_gmt":"2017-10-11T23:07:27","slug":"porting-windows-projects-to-linux-with-windows-10-linux-subsystem","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/porting\/lxss\/","title":{"rendered":"Porting Windows projects to Linux with Windows 10 Linux Subsystem"},"content":{"rendered":"<p>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.<\/p>\n<ol>\n<li>Open Visual Studio and create a regular Win32 Console application:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/01-winprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3293\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/01-winprj.png\" alt=\"01-winprj\" width=\"806\" height=\"550\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/01-winprj.png 806w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/01-winprj-300x205.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/01-winprj-130x90.png 130w\" sizes=\"(max-width: 806px) 100vw, 806px\" \/><\/a><\/li>\n<li>Open the stdafx.h file and remove references to <strong>tchar.h<\/strong> and <strong>targetver.h<\/strong> that are not available on Linux:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/02-stdafx.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3294\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/02-stdafx.png\" alt=\"02-stdafx\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/02-stdafx.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/02-stdafx-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/02-stdafx-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>Modify the main() function to print a basic &#8220;Hello, world&#8221; message and build the project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/03-hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3295\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/03-hello.png\" alt=\"03-hello\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/03-hello.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/03-hello-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/03-hello-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>Set a breakpoint on the printf() line and begin debugging with F5 to ensure that the native Windows build runs:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/04-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3296\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/04-debug.png\" alt=\"04-debug\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/04-debug.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/04-debug-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/04-debug-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>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 -&gt; Turn Windows features on or off:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/05-wsl.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3297\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/05-wsl.png\" alt=\"05-wsl\" width=\"553\" height=\"466\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/05-wsl.png 553w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/05-wsl-300x253.png 300w\" sizes=\"(max-width: 553px) 100vw, 553px\" \/><\/a><\/li>\n<li>Go back to Visual Studio and select Project-&gt;Add VisualGDB Configuration-&gt;New Linux Configuration:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/06-addlinux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3298\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/06-addlinux.png\" alt=\"06-addlinux\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/06-addlinux.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/06-addlinux-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/06-addlinux-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>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:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/07-msbuild.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3299\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/07-msbuild.png\" alt=\"07-msbuild\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/07-msbuild.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/07-msbuild-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>On the next page select &#8220;Use the Windows 10 Linux Subsystem&#8221; and proceed with the default toolchain:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/08-lxss.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3300\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/08-lxss.png\" alt=\"08-lxss\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/08-lxss.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/08-lxss-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>VisualGDB will automatically detect the path mappings between the Windows and Linux subsystems, so simply click &#8220;Finish&#8221; on the last page:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/09-map.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3301\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/09-map.png\" alt=\"09-map\" width=\"822\" height=\"641\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/09-map.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/09-map-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>VisualGDB will create a new solution platform called &#8216;VisualGDB&#8217; and will insert the new configuration there. Ensure that you can build the project by pressing Ctrl-Shift-B:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/10-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3302\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/10-build.png\" alt=\"10-build\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/10-build.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/10-build-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/10-build-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>Set a breakpoint in main() and start debugging by pressing F5:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/11-main.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3303\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/11-main.png\" alt=\"11-main\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/11-main.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/11-main-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/11-main-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>Include the &lt;unistd.h&gt; 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 &#8220;Go&#8221; button to open the file, or simply begin using any functions declared in it and IntelliSense will automatically recognize them:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/12-unistd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3304\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/12-unistd.png\" alt=\"12-unistd\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/12-unistd.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/12-unistd-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/12-unistd-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>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&#8217;t need to re-synchronize them. You can get a quick overview of the directories seen by VisualGDB via VisualGDB Project Properties -&gt; IntelliSense Directories:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/13-includedirs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3305\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/13-includedirs.png\" alt=\"13-includedirs\" width=\"825\" height=\"594\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/13-includedirs.png 825w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/13-includedirs-300x216.png 300w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/a><\/li>\n<li>As long as you are using MSBuild, you can use the regular Visual Studio project properties to set various build-related settings:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/14-precomp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3306\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/14-precomp.png\" alt=\"14-precomp\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/14-precomp.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/14-precomp-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/14-precomp-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<li>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:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/15-inc1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3308\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/15-inc1.png\" alt=\"15-inc\" width=\"1199\" height=\"802\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/15-inc1.png 1199w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/15-inc1-300x201.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/10\/15-inc1-1024x685.png 1024w\" sizes=\"(max-width: 1199px) 100vw, 1199px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to port native Win32 projects to Linux using VisualGDB and the Windows 10 Linux Subsystem. Before<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[84],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3292"}],"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=3292"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3292\/revisions"}],"predecessor-version":[{"id":3309,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/3292\/revisions\/3309"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=3292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=3292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=3292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}