{"id":24310,"date":"2019-05-10T17:13:54","date_gmt":"2019-05-10T17:13:54","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=24310"},"modified":"2020-01-27T16:43:38","modified_gmt":"2020-01-27T16:43:38","slug":"linux-development-with-c-in-visual-studio-2019-wsl-asan-for-linux-separation-of-build-and-debug","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/linux-development-with-c-in-visual-studio-2019-wsl-asan-for-linux-separation-of-build-and-debug\/","title":{"rendered":"Linux Development with C++ in Visual Studio 2019: WSL, ASan for Linux, Separation of Build and Debug"},"content":{"rendered":"<p>In Visual Studio 2019 you can target both Windows and Linux from the comfort of a single IDE. In <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 version 16.1 Preview 3<\/a> we announced several new features specific to the <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/download-install-and-setup-the-linux-development-workload?view=vs-2019\">Linux Workload<\/a>: native support for the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/c-with-visual-studio-2019-and-windows-subsystem-for-linux-wsl\/\">Windows Subsystem for Linux (WSL)<\/a>, <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/addresssanitizer-asan-for-the-linux-workload-in-visual-studio-2019\/\">AddressSanitizer integration<\/a>, and the ability to separate build and debug targets. If you\u2019re just getting started with cross-platform development, I recommend trying our <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/c-with-visual-studio-2019-and-windows-subsystem-for-linux-wsl\/\">native support for WSL<\/a>.<\/p>\n<h4>Native support for the Windows Subsystem for Linux (WSL)<\/h4>\n<p>Visual Studio now provides native support for using C++ with <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/wsl\/about\">WSL<\/a>. WSL lets you run a lightweight Linux environment directly on Windows, including most command-line tools, utilities, and applications. In Visual Studio you no longer need to add a remote connection or configure SSH in order to build and debug on your local WSL installation. Check out our <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/c-with-visual-studio-2019-and-windows-subsystem-for-linux-wsl\/\" target=\"_blank\" rel=\"noopener noreferrer\">post on native support for WSL in Visual Studio<\/a> to learn more and follow a step-by-step guide on getting started.<\/p>\n<p><img decoding=\"async\" width=\"622\" height=\"166\" class=\"wp-image-24311 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-11.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-11.png 622w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-11-300x80.png 300w\" sizes=\"(max-width: 622px) 100vw, 622px\" \/><\/p>\n<h4>AddressSanitizer for the Linux Workload<\/h4>\n<p>In Visual Studio 2019 version 16.1 Preview 3 we have integrated <a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\">AddressSanitizer<\/a> (ASan) into Visual Studio for Linux projects. ASan is a runtime memory error detector for C\/C++. You can enable ASan for <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/configure-a-linux-project?view=vs-2019\">MSBuild-based Linux projects<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/cmake-linux-project?view=vs-2019\">CMake projects<\/a> that target a remote Linux machine or WSL. Check out our <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/addresssanitizer-asan-for-the-linux-workload-in-visual-studio-2019\/\">post on AddressSanitizer for the Linux Workload in Visual Studio<\/a> for more information.<\/p>\n<p><img decoding=\"async\" width=\"724\" height=\"180\" class=\"wp-image-24312 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-12.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-12.png 724w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-12-300x75.png 300w\" sizes=\"(max-width: 724px) 100vw, 724px\" \/><\/p>\n<h4>Separate build and debug targets for Linux projects<\/h4>\n<p><strong>Update 1\/27\/2020: In Visual Studio 2019 version 16.5 and later you can leverage Visual Studio&#8217;s <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/cmake-linux-targeting-and-intellisense-improvements-in-visual-studio-2019-version-16-5-preview-2\/#wsl\">native support for WSL when separating your build system from your remote deploy system<\/a>.<\/strong><\/p>\n<p>You can now separate your remote build machine from your remote debug machine for both <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/configure-a-linux-project?view=vs-2019\">MSBuild-based Linux projects<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/cmake-linux-project?view=vs-2019\">CMake projects<\/a> that target a remote Linux machine. For example, you can now cross-compile on x64 and deploy to an ARM device when targeting IoT scenarios.<\/p>\n<p>For a MSBuild-based Linux project, you can specify a new remote debug machine in the project\u2019s Property Pages (Configuration Properties &gt; Debugging &gt; Remote Debug Machine). By default, this value is synchronized with your remote build machine (Configuration Properties &gt; General &gt; Remote Build Machine). <img decoding=\"async\" width=\"1244\" height=\"892\" class=\"wp-image-24313 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-13.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-13.png 1244w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-13-300x215.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-13-768x551.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-13-1024x734.png 1024w\" sizes=\"(max-width: 1244px) 100vw, 1244px\" \/><\/p>\n<p>The drop-down menu is populated with all established remote connections. To <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/connect-to-your-remote-linux-computer?view=vs-2019\">add a new remote connection<\/a>, navigate to Tools &gt; Options &gt; Cross Platform &gt; Connection Manager or search for \u201cConnection Manager\u201d in the search bar at the top of your screen. You can also specify a new remote deploy directory in the project\u2019s Property Pages (Configuration Properties &gt; General &gt; Remote Deploy Directory).<\/p>\n<p>By default, only the files necessary for the process to debug will be deployed to the remote debug machine. You can view\/configure which source files will be deployed via the Solution Explorer. When you click on a source file, you will see a preview of its File Properties directly below the Solution Explorer. You can also right-click on a source file and select \u201cProperties.\u201d<\/p>\n<p><img decoding=\"async\" width=\"513\" height=\"1279\" class=\"wp-image-24314 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-14.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-14.png 513w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-14-120x300.png 120w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-14-411x1024.png 411w\" sizes=\"(max-width: 513px) 100vw, 513px\" \/><\/p>\n<p>The \u201cContent\u201d property specifies whether the file will be deployed to the remote debug machine. You can also disable deployment entirely by navigating to Property Pages &gt; Configuration Manager and unchecking \u201cDeploy\u201d for the desired configuration.<\/p>\n<p>If you want complete control over your project\u2019s deployment (e.g. some files you want to deploy are outside of your solution or you want to customize your remote deploy directory per file\/directory), then you can append the following code block(s) to your .vcxproj file:<\/p>\n<pre class=\"font-size:14 toolbar:2 show-lang:2 plain:false show-plain:3 plain-toggle:false copy:false popup:false expand-toggle:false decode-attributes:false trim-whitespace:false trim-code-tag:false mixed:false show_mixed:false lang:default highlight:0 decode:true \">&lt;ItemGroup&gt;\r\n   &lt;RemoteDeploy Include=\"__example.cpp\"&gt;\r\n&lt;!-- This is the source Linux machine, can be empty if DeploymentType is LocalRemote --&gt;\r\n      &lt;SourceMachine&gt;$(RemoteTarget)&lt;\/SourceMachine&gt;\r\n      &lt;TargetMachine&gt;$(RemoteDebuggingTarget)&lt;\/TargetMachine&gt;\r\n      &lt;SourcePath&gt;~\/example.cpp&lt;\/SourcePath&gt;\r\n      &lt;TargetPath&gt;~\/example.cpp&lt;\/TargetPath&gt;\r\n&lt;!-- DeploymentType can be LocalRemote, in which case SourceMachine will be empty and SourcePath is a local file on Windows --&gt;\r\n      &lt;DeploymentType&gt;RemoteRemote&lt;\/DeploymentType&gt;\r\n&lt;!-- Indicates whether the deployment contains executables --&gt;\r\n      &lt;Executable&gt;true&lt;\/Executable&gt;\r\n   &lt;\/RemoteDeploy&gt;\r\n&lt;\/ItemGroup&gt;<\/pre>\n<p>For CMake projects that target a remote Linux machine, you can specify a new remote debug machine via <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/build\/configure-cmake-debugging-sessions?view=vs-2019\">launch.vs.json<\/a>. By default, the value of \u201cremoteMachineName\u201d will be synchronized with the \u201cremoteMachineName\u201d property in <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/build\/cmakesettings-reference?view=vs-2019\">CMakeSettings.json<\/a>, which corresponds to your remote build machine. These properties no longer need to match, and the value of \u201cremoteMachineName\u201d in launch.vs.json will dictate the remote machine used for deploy and debug.<\/p>\n<p><img decoding=\"async\" width=\"894\" height=\"427\" class=\"wp-image-24315 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-15.png\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-15.png 894w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-15-300x143.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/05\/word-image-15-768x367.png 768w\" sizes=\"(max-width: 894px) 100vw, 894px\" \/><\/p>\n<p>IntelliSense will suggest all a list of all established remote connections, but you can <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/linux\/connect-to-your-remote-linux-computer?view=vs-2019\">add a new remote connection<\/a> by navigating to Tools &gt; Options &gt; Cross Platform &gt; Connection Manager or searching for \u201cConnection Manager\u201d in the search bar at the top of your screen.<\/p>\n<p>If you want complete control over your deployment, you can append the following code block(s) to launch.vs.json:<\/p>\n<pre class=\"font-size:14 toolbar:2 show-lang:2 show-plain:3 lang:default highlight:0 decode:true\">\"disableDeploy\": false,\r\n\"deployDirectory\": \"~\\foo\",\r\n\"deploy\" : [\r\n   {\r\n      \"sourceMachine\": \"127.0.0.1 (username=example1, port=22, authentication=Password)\",\r\n      \"targetMachine\": \"192.0.0.1 (username=example2, port=22, authentication=Password)\",\r\n      \"sourcePath\": \"~\/example.cpp\",\r\n      \"targetPath\": \"~\/example.cpp\",\r\n      \"executable\": \"false\"\r\n   }\r\n]<\/pre>\n<h4>Resolved issues<\/h4>\n<p>The best way to report a problem or suggest a feature to the C++ team is via <a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\">Developer Community<\/a>. The following feedback tickets related to C++ cross-platform development have been recently resolved in Visual Studio 2019 16.1 Preview 2 or Preview 3:<\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/542771\/no-configurations-when-using-cpppropertiesjson.html\">No configurations when using CppProperties.json<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/544586\/unable-to-attach-process-of-linux-vm.html\">Unable to attach process of linux vm<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/504808\/cmake-linux-binary-deployment-fails-with-wsl.html\">cmake linux binary deployment fails with WSL<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/487332\/infobar-appears-when-open-existing-cmake-cache-fai.html\">Infobar appears when open existing CMake cache fails<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/491168\/vs2017-crashes-when-building-remote-linux-cmake-pr.html\">VS2017 crashes if SSH has connection error while building remote Linux CMake project<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/466702\/ctest-timeout-feature-doesnt-work-in-test-explorer.html\">CTest timeout feature doesn&#8217;t work in test explorer<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/447029\/cmake-any-minor-change-to-cmakeliststxt-triggers-a.html\">CMake: Any minor change to CMakeLists.txt triggers a full cache regeneration<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/433185\/cmake-intellisense-preprocessor-definitions-in-cma-1.html\">CMake + Intellisense: Preprocessor definitions in CMakeLists do not work with quoted strings<\/a><\/p>\n<p><a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/389085\/intellisense-problem-for-linux-makefile-project.html\">Intellisense problem for Linux Makefile project<\/a><\/p>\n<h4>Talk to us!<\/h4>\n<p>Do you have feedback on our Linux tooling in Visual Studio? Pick a time to <a href=\"https:\/\/outlook.office365.com\/owa\/calendar\/VisualStudioCustomerResearchCrossPlatformDevelopment@microsoft.onmicrosoft.com\/bookings\/\">chat with the C++ cross-platform team<\/a> and share your experiences \u2013 the good and the bad \u2013 to help us prioritize and build the right features for you! We can also be reached via the comments below, email (<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>), and Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@<\/a><a href=\"https:\/\/twitter.com\/visualc\">VisualC<\/a>) and (<a href=\"https:\/\/twitter.com\/erikasweet_\">@erikasweet_<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Visual Studio 2019 you can target both Windows and Linux from the comfort of a single IDE. In Visual Studio 2019 version 16.1 Preview 3 we announced several new features specific to the Linux Workload: native support for the Windows Subsystem for Linux (WSL), AddressSanitizer integration, and the ability to separate build and debug [&hellip;]<\/p>\n","protected":false},"author":2953,"featured_media":24313,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270,1,266,239,317,279,230],"tags":[],"class_list":["post-24310","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","category-cplusplus","category-cmake","category-diagnostics","category-iot","category-linux","category-new-feature"],"acf":[],"blog_post_summary":"<p>In Visual Studio 2019 you can target both Windows and Linux from the comfort of a single IDE. In Visual Studio 2019 version 16.1 Preview 3 we announced several new features specific to the Linux Workload: native support for the Windows Subsystem for Linux (WSL), AddressSanitizer integration, and the ability to separate build and debug [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/2953"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=24310"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24310\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/24313"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=24310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=24310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=24310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}