Download, Install, and Set Up The Linux Workload
Download, Install, and Set Up The Linux Workload
Download, Install, and Set Up The Linux Workload
Linux projects are supported in Visual Studio 2017 and later. To see the documentation for these versions, set
the Visual Studio Version selector control for this article to Visual Studio 2017 or Visual Studio 2019. 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.
You can work on your existing code base that uses CMake without having to convert it to a Visual Studio project.
If your code base is cross-platform, you can target both Windows and Linux from within Visual Studio. For
example, you can edit, build, and debug your code on Windows using Visual Studio. Then, quickly retarget the
project for Linux to build and debug in a Linux environment. Linux header files are automatically copied to your
local machine. Visual Studio uses them to provide full IntelliSense support (Statement Completion, Go to
Definition, and so on).
For any of these scenarios, the Linux development with C++ workload is required.
2. Look for the installer under the Apps results and double-click it. When the installer opens, choose
Modify , and then click on the Workloads tab. Scroll down to Other toolsets and select the Linux
development with C++ workload.
3. If you're targeting IoT or embedded platforms, go to the Installation details pane on the right. Under
Linux development with C++ , expand Optional Components , and choose the components you
need. CMake support for Linux is selected by default.
4. Click Modify to continue with the installation.
Options for creating a Linux environment
If you don't already have a Linux machine, you can create a Linux Virtual Machine on Azure. For more
information, see Quickstart: Create a Linux virtual machine in the Azure portal.
On Windows 10 and later, you can install and target your favorite Linux distro on the Windows Subsystem for
Linux (WSL). For more information, see Windows Subsystem for Linux Installation Guide for Windows 10. If
you're unable to access the Windows Store, you can manually download the WSL distro packages. WSL is a
convenient console environment, but it's not recommended for graphical applications.
Linux projects in Visual Studio require the following dependencies to be installed on your remote Linux system
or WSL:
A compiler - Visual Studio 2019 and later have full support for GCC and Clang.
gdb - Visual Studio automatically launches gdb on the Linux system, and uses the front end of the Visual
Studio debugger to provide a full-fidelity debugging experience on Linux.
rsync and zip - the inclusion of rsync and zip allows Visual Studio to extract header files from your Linux
system to the Windows filesystem for use by IntelliSense.
make
openssh-ser ver (remote Linux systems only) - Visual Studio connects to remote Linux systems over a
secure SSH connection.
CMake (CMake projects only) - You can install Microsoft's statically linked CMake binaries for Linux.
ninja-build (CMake projects only) - Ninja is the default generator for Linux and WSL configurations in
Visual Studio 2019 version 16.6 or later.
The following commands assume you're using g++ instead of clang.
Linux projects in Visual Studio require the following dependencies to be installed on your remote Linux system
or WSL:
gcc - Visual Studio 2017 has full support for GCC.
gdb - Visual Studio automatically launches gdb on the Linux system and uses the front end of the Visual
Studio debugger to provide a full-fidelity debugging experience on Linux.
rsync and zip - the inclusion of rsync and zip allows Visual Studio to extract header files from your Linux
system to the Windows filesystem to use for IntelliSense.
make
openssh-ser ver - Visual Studio connects to remote Linux systems over a secure SSH connection.
CMake (CMake projects only) - You can install Microsoft's statically linked CMake binaries for Linux.
sudo apt-get install openssh-server g++ gdb make ninja-build rsync zip
You may be prompted for your root password to run the sudo command. If so, enter it and continue.
Once complete, the required services and tools are installed.
2. Ensure the ssh service is running on your Linux computer by running:
This command starts the service and runs it in the background, ready to accept connections.
Fedora on WSL
Fedora uses the dnf package installer. To download g++ , gdb , make , rsync , ninja-build , and zip , run:
zip and rsync are required for automatic syncing of Linux headers with Visual Studio for Intellisense support.
ninja-build is only required for CMake projects.
sudo dnf install openssh-server gcc-g++ gdb ninja-build make rsync zip
You may be prompted for your root password to run the sudo command. If so, enter it and continue.
Once complete, the required services and tools are installed.
2. Ensure the ssh service is running on your Linux computer by running:
This command starts the service and runs it in the background, ready to accept connections.
Next Steps
You're now ready to create or open a Linux project and configure it to run on the target system. For more
information, see:
Create a new Linux MSBuild C++ project
Configure a Linux CMake project
Connect to your target Linux system in Visual
Studio
11/22/2022 • 10 minutes to read • Edit Online
NOTE
Starting in Visual Studio 2019 version 16.5, Visual Studio supports secure, Federal Information Processing Standard (FIPS)
140-2 compliant cryptographic connections to Linux systems for remote development. To use a FIPS-compliant
connection, follow the steps in Set up FIPS-compliant secure remote Linux development instead.
2. If you'd like the ssh server to start automatically when the system boots, enable it using systemctl:
EN T RY DESC RIP T IO N
Private key file Private key file created for ssh connection
You can use either a password or a key file and passphrase for authentication. For many development
scenarios, password authentication is sufficient, but key files are more secure. If you already have a key
pair, it's possible to reuse it. Currently Visual Studio only supports RSA and DSA keys for remote
connections.
4. Choose the Connect button to attempt a connection to the remote computer.
If the connection succeeds, Visual Studio configures IntelliSense to use the remote headers. For more
information, see IntelliSense for headers on remote systems.
If the connection fails, the entry boxes that need to be changed are outlined in red.
If you use key files for authentication, make sure the target machine's SSH server is running and
configured properly.
If you have trouble connecting to WSL on localhost , see Fix WSL localhost connection problems.
Encryption aes128-cbc
aes128-ctr
aes192-cbc
aes192-ctr
aes256-cbc
aes256-ctr
HMAC hmac-sha2-256
hmac-sha2-512
3des-cbc
aes128-cbc
aes192-cbc
aes256-cbc
...
[email protected]
[email protected]
The output lists all the encryption, HMAC, key exchange, and host key algorithms supported by your SSH server.
If the list doesn't include algorithms supported by Visual Studio, then you'll need to upgrade your SSH server
before proceeding.
You can enable algorithms supported by Visual Studio by editing /etc/ssh/sshd_config on the remote machine.
The following examples show how to add various types of algorithms to that configuration file.
These examples can be added anywhere in /etc/ssh/sshd_config . Ensure that they're on their own lines.
After editing the file, restart the SSH server ( sudo service ssh restart on Ubuntu) and attempt to connect again
from Visual Studio.
Cipher example
Add: Ciphers <algorithms to enable>
For example: Ciphers aes128-cbc,aes256-cbc
HMAC example
Add: MACs <algorithms to enable>
For example: MACs hmac-sha2-256,hmac-sha2-512
Key exchange example
Add: KexAlgorithms <algorithms to enable>
For example: KexAlgorithms ecdh-sha2-nistp256,ecdh-sha2-nistp384
Host key example
Add: HostKeyAlgorithms <algorithms to enable>
For example: HostKeyAlgorithms ssh-dss,ssh-rsa
rsync is also used by Visual Studio's CMake support to copy source files to the remote system. If you can't
enable TCP port forwarding, you can use sftp as your remote copy sources method. sftp is often slower than
rsync , but doesn't have a dependency on TCP port forwarding. You can manage your remote copy sources
method with the remoteCopySourcesMethod property in the CMake Settings Editor. If TCP port forwarding is
disabled on your remote system, you'll see an error in the CMake output window the first time it invokes rsync .
gdbserver can be used for debugging on embedded devices. If you can't enable TCP port forwarding, then you
must use gdb for all remote debugging scenarios. gdb is used by default when debugging projects on a
remote system.
Visual Studio's Linux support has a dependency on TCP port forwarding. Both rsync and gdbserver are
affected if TCP port forwarding is disabled on your remote system. If this dependency impacts you, vote for this
suggestion ticket on Developer Community.
Connect to WSL
In Visual Studio 2017, you use the same steps to connect to WSL as you use for a remote Linux machine. Use
localhost for the Host Name .
Starting in Visual Studio 2019 version 16.1, Visual Studio has native support for using C++ with the Windows
Subsystem for Linux (WSL). That means you can build and debug on your local WSL installation directly. You no
longer need to add a remote connection or configure SSH. You can find details on how to install WSL here.
To configure your WSL installation to work with Visual Studio, you need the following tools installed: gcc or
clang , gdb , make , ninja-build (only required for CMake projects using Visual Studio 2019 version 16.6 or
later), rsync , and zip . You can install them on distros that use apt by using this command, which also installs
the g++ compiler:
Port 23
If you're connecting using a password, ensure that the following is set in /etc/ssh/sshd_config :
After making these changes, restart the SSH server ( sudo service ssh restart on Ubuntu).
Then retry your connection to localhost using port 23.
For more information, see Download, install, and set up the Linux workload.
To configure an MSBuild project for WSL, see Configure a Linux project. To configure a CMake project for WSL,
see Configure a Linux CMake project. To follow step-by-step instructions for creating a simple console
application with WSL, check out this introductory blog post on C++ with Visual Studio 2019 and the Windows
Subsystem for Linux (WSL).
See Also
Configure a Linux project
Configure a Linux CMake project
Deploy, run, and debug your Linux project
Configure CMake debugging sessions
Set up FIPS-compliant secure remote Linux
development
11/22/2022 • 5 minutes to read • Edit Online
Linux support is available in Visual Studio 2017 and later. FIPS-compliant secure remote Linux development is
available in Visual Studio 2019 version 16.5 and later.
Federal Information Processing Standard (FIPS) Publication 140-2 is a U.S. government standard for
cryptographic modules. Implementations of the standard are validated by NIST. Windows has validated support
for FIPS-compliant cryptographic modules. In Visual Studio 2019 version 16.5 and later, you can use a secure,
FIPS-compliant cryptographic connection to your Linux system for remote development.
Here's how to set up a secure, FIPS-compliant connection between Visual Studio and your remote Linux system.
This guide is applicable when you build CMake or MSBuild Linux projects in Visual Studio. This article is the
FIPS-compliant version of the connection instructions in Connect to your remote Linux computer.
2. If you'd like the ssh server to start automatically when the system boots, enable it using systemctl :
3. Open /etc/ssh/sshd_config as root. Edit (or add, if they don't exist) the following lines:
Ciphers aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc
HostKeyAlgorithms ssh-rsa
KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-
group14-sha1
MACs hmac-sha2-256,hmac-sha1
NOTE
ssh-rsa is the only FIPS compliant host key algorithm VS supports. The aes*-ctr algorithms are also FIPS
compliant, but the implementation in Visual Studio isn't approved. The ecdh-* key exchange algorithms are FIPS
compliant, but Visual Studio doesn't support them.
You're not limited to these options. You can configure ssh to use other ciphers, host key algorithms, and
so on. Some other relevant security options you may want to consider are PermitRootLogin ,
PasswordAuthentication , and PermitEmptyPasswords . For more information, see the man page for
sshd_config or the article SSH Server Configuration.
4. After saving and closing sshd_config , restart the ssh server to apply the new configuration:
Next, you'll create an RSA key pair on your Windows computer. Then you'll copy the public key to the remote
Linux system for use by ssh .
To create and use an RSA key file
1. On the Windows machine, generate a public/private RSA key pair by using this command:
The command creates a public key and a private key. By default, the keys are saved to
%USERPROFILE%\.ssh\id_rsa and %USERPROFILE%\\.ssh\\id_rsa.pub . (In PowerShell, use $env:USERPROFILE
instead of the cmd macro %USERPROFILE% ) If you change the key name, use the changed name in the steps
that follow. We recommend you use a passphrase for increased security.
2. From Windows, copy the public key to the Linux machine:
3. On the Linux system, add the key to the list of authorized keys, and ensure the file has the correct
permissions:
4. Now, you can test to see if the new key works in ssh . Use it to sign in from Windows:
You've successfully set up ssh , created and deployed encryption keys, and tested your connection. Now you're
ready to set up the Visual Studio connection.
3. In the Connect to Remote System dialog, enter the connection details of your remote machine.
EN T RY DESC RIP T IO N
Private key file Private key file created for ssh connection
Change the authentication type to Private Key . Enter the path to your private key in the Private key file
field. You can use the Browse button to navigate to your private key file instead. Then, enter the
passphrase used to encrypt your private key file in the Passphrase field.
4. Choose the Connect button to attempt a connection to the remote computer.
If the connection succeeds, Visual Studio configures IntelliSense to use the remote headers. For more
information, see IntelliSense for headers on remote systems.
If the connection fails, the entry boxes that need to be changed are outlined in red.
For more information on troubleshooting your connection, see Connect to your remote Linux computer.
WARNING
Enabling FIPS mode may cause some applications to break or behave unexpectedly. For more information, see the blog
post Why We're Not Recommending "FIPS mode" Anymore.
Additional resources
Microsoft documentation on FIPS 140 validation
FIPS 140-2: Security Requirements for Cryptographic Modules (from NIST)
Cryptographic Algorithm Validation Program: Validation Notes (from NIST)
Microsoft blog post on Why We're Not Recommending "FIPS mode" Anymore
SSH Server Configuration
See Also
Configure a Linux project
Configure a Linux CMake project
Connect to your remote Linux computer
Deploy, run, and debug your Linux project
Configure CMake debugging sessions
ConnectionManager reference
11/22/2022 • 4 minutes to read • Edit Online
Syntax
ConnectionManager.exe command [arguments] [options]
Authenticates and adds a new connection. By default, it uses port 22 and password authentication. (You'll
be prompted to enter a password.) Use both - -password and --privatekey to specify a password for a
private key.
clean
The host key fingerprint presented by the server. Use this option with list to view a connection's
fingerprint.
-i
Same as --privatekey .
-n , --dry-run
Disable sending usage data back to Microsoft. Usage data is collected and sent back to Microsoft unless
the --no-telemetry flag is passed.
--no-verify
Same as --password .
--previous
Indicates that the connection(s) will be read from the previous version of connection manager, updated,
and written to the new version.
-q , --quiet
Examples
This command adds a connection for a user named "user" on localhost. The connection uses a key file for
authentication, found in %USERPROFILE%.ssh\id_rsa.
ConnectionManager.exe add [email protected] --privatekey "%USERPROFILE%\.ssh\id_rsa"
This command removes the connection that has ID 1975957870 from the list of connections.
authentication type The type of authentication used for the connection such as:
"password" , "privatekey" .
To create a connection with the authentication type set to
"privatekey" :
ConnectionManager.exe add [email protected] --
privatekey "%USERPROFILE%\.ssh\id_rsa"
password The password for the connection. Change the password for
the specified connection with:
ConnectionManager.exe modify -21212121 --property
password="xyz"
username The name of the user logged into the remote computer.
To add a connection for a user named "user" on localhost:
ConnectionManager.exe add [email protected]
See also
Connect to your target Linux system in Visual Studio
Create a Linux MSBuild C++ project in Visual
Studio
11/22/2022 • 2 minutes to read • Edit Online
Blink (Raspberr y) Project targeted for a Raspberry Pi device, with sample code
that blinks an LED
P RO JEC T T Y P E DESC RIP T IO N
Console Application (Linux) Project targeted for any Linux computer, with sample code
that outputs text to the console
Empty Project (Linux) Project targeted for any Linux computer, with no sample
code
Makefile Project (Linux) Project targeted for any Linux computer, built using a
standard Makefile build system
First, make sure you have the Linux Development Workload for Visual Studio installed. For more
information, see Download, install, and set up the Linux workload.
When you create a new C++ project for Linux in Visual Studio, you can choose to create a Visual Studio project
or a CMake project. This article describes how to create a Visual Studio project. In general, for new projects that
might include open-source code or you intend to compile for cross-platform development, we recommend you
use CMake with Visual Studio. With a CMake project, you can build and debug the same project on both
Windows and Linux. For more information, see Create and configure a Linux CMake Project.
If you have an existing Windows Visual Studio solution that you would like to extend to compile for Linux, and
CMake isn't an option, then you can add a Visual Studio Linux project to the Windows solution, along with a
Shared Items project. Put the code that is shared between both platforms in the Shared Items project, and add
a reference to that project from the Windows and Linux projects.
Console Application Project targeted for any Linux computer, with sample
code that outputs text to the console
Empty Project Project targeted for any Linux computer, with no sample
code
Makefile Project Project targeted for any Linux computer, built using a
standard Makefile build system
CMake Project Project targeted for any Linux computer, built using the
CMake build system
Next steps
Configure a Linux MSBuild project
Configure a Linux MSBuild C++ project in Visual
Studio
11/22/2022 • 5 minutes to read • Edit Online
General settings
To view configuration options, select the Project > Proper ties menu, or right-click on the project in Solution
Explorer and select Proper ties from the context menu. The General settings appear.
By default, an executable (.out) is built. To build a static or dynamic library, or to use an existing Makefile, use the
Configuration Type setting.
If you're building for Windows Subsystem for Linux (WSL), WSL Version 1 is limited to 64 parallel compilation
processes. This is governed by the Max Parallel Compilation Jobs setting in Configuration proper ties >
C/C++ > General .
Regardless of the WSL version you are using, if you intend to use more than 64 parallel compilation processes,
we recommend that you build with Ninja--which generally will be faster and more reliable. To build with Ninja,
use the Enable Incremental Build setting in Configuration proper ties > General .
For more information about the settings in the property pages, see Linux Project Property Page Reference.
Remote settings
To change settings related to the remote Linux computer, configure the remote settings that appear under
General.
To specify a remote target Linux computer, use the Remote Build Machine entry. This will allow you to
select one of the connections created previously. To create a new entry, see the Connecting to Your
Remote Linux Computer section.
Visual Studio 2019 version 16.7 and later: To target Windows Subsystem for Linux (WSL), set the
Platform Toolset drop-down to GCC for Windows Subsystem for Linux . The other remote options
will disappear and the path to the default WSL shell will appear in their place:
If you have side-by-side WSL installations, you can specify a different path here. For more information
about managing multiple distros, see Manage and configure Windows Subsystem for Linux.
You can specify a different target for debugging on the Configuration Proper ties > Debugging page.
The Remote Build Root Director y determines the root location of where the project is built on the
remote Linux computer. This will default to ~/projects unless changed.
The Remote Build Project Director y is where this specific project will be built on the remote Linux
computer. This will default to $(RemoteRootDir)/$(ProjectName) , which will expand to a directory
named after the current project, under the root directory set above.
NOTE
To change the default C and C++ compilers, or the Linker and Archiver used to build the project, use the appropriate
entries in the C/C++ > General section and the Linker > General section. You can specify a certain version of GCC or
Clang, for example. For more information, see C/C++ Properties (Linux C++) and Linker Properties (Linux C++).
When building on remote systems, the source files on your development PC are copied to the Linux computer
and compiled there. By default, all sources in the Visual Studio project are copied to the locations set in the
settings above. However, additional sources can also be added to the list, or copying sources can be turned off
entirely, which is the default for a Makefile project.
Sources to copy determines which sources are copied to the remote computer. By default, the
@(SourcesToCopyRemotely) defaults to all source code files in the project, but doesn't include any
asset/resource files, such as images.
Copy sources can be turned on and off to enable and disable the copying of source files to the remote
computer.
Additional sources to copy allows you to add additional source files, which will be copied to the
remote system. You can specify a semi-colon delimited list, or you can use the := syntax to specify a local
and remote name to use:
C:\Projects\ConsoleApplication1\MyFile.cpp:=~/projects/ConsoleApplication1/ADifferentName.cpp;C:\Projects\ConsoleApplication1\MyFile2.cpp:=~/projects/ConsoleApplicatio
Build events
Since all compilation is happening on a remote computer (or WSL), several additional Build Events have been
added to the Build Events section in Project Properties. These are Remote Pre-Build Event , Remote Pre-Link
Event , and Remote Post-Build Event , and will occur on the remote computer before or after the individual
steps in the process.
IntelliSense for headers on remote systems
When you add a new connection in Connection Manager , Visual Studio automatically detects the include
directories for the compiler on the remote system. Visual Studio then zips up and copies those files to a
directory on your local Windows machine. After that, whenever you use that connection in a Visual Studio or
CMake project, the headers in those directories are used to provide IntelliSense.
NOTE
In Visual Studio 2019 version 16.5 and later, the remote header copy has been optimized. Headers are now copied on-
demand when opening a Linux project or configuring CMake for a Linux target. The copy occurs in the background on a
per-project basis, based on the project's specified compilers. For more information, see Improvements to Accuracy and
Performance of Linux IntelliSense.
This functionality depends on the Linux machine having zip installed. You can install zip by using this apt-get
command:
To manage your header cache, navigate to Tools > Options, Cross Platform > Connection Manager >
Remote Headers IntelliSense Manager . To update the header cache after making changes on your Linux
machine, select the remote connection and then select Update . Select Delete to remove the headers without
deleting the connection itself. Select Explore to open the local directory in File Explorer . Treat this folder as
read-only. To download headers for an existing connection that was created before Visual Studio 2017 version
15.3, select the connection and then select Download .
You can enable logging to help troubleshoot problems:
See also
Set compiler and build properties
C++ General Properties (Linux C++)
VC++ Directories (Linux C++)
Copy Sources Project Properties (Linux C++)
Build Event Properties (Linux C++)
Deploy, run, and debug your Linux MSBuild project
11/22/2022 • 7 minutes to read • Edit Online
Linux support is available in Visual Studio 2017 and later. To see the documentation for these versions, set the
Version drop-down located above the table of contents to Visual Studio 2017 or Visual Studio 2019 .
Once you've created a MSBuild-based Linux C++ project in Visual Studio and you've connected to the project
using the Linux Connection Manager, you can run and debug the project. You compile, execute, and debug the
code on the remote target.
Visual Studio 2019 version 16.1 and later: You can target different Linux systems for debugging and
building. For example, you can cross-compile on x64 and deploy to an ARM device when targeting IoT scenarios.
For more information, see Specify different machines for building and debugging later in this article.
There are several ways to interact with and debug your Linux project.
Debug using traditional Visual Studio features, such as breakpoints, watch windows, and hovering over a
variable. Using these methods, you may debug as you normally would for other project types.
View output from the target computer in the Linux Console window. You can also use the console to send
input to the target computer.
In gdbser ver mode, GDB is run locally, which connects to gdbserver on the remote system.
In gdb mode, the Visual Studio debugger drives GDB on the remote system. This is a better option
if the local version of GDB isn't compatible with the version installed on the target computer. This is
the only mode that the Linux Console window supports.
NOTE
If you are unable to hit breakpoints in gdbserver debugging mode, try gdb mode. gdb must first be installed on
the remote target.
2. Select the remote target using the standard Debug toolbar in Visual Studio.
When the remote target is available, you'll see it listed by either name or IP address.
If you haven't connected to the remote target yet, you'll see an instruction to use Linux Connection
Manager to connect to the remote target.
3. Set a breakpoint by clicking in the left gutter of some code that you know will execute.
A red dot appears on the line of code where you set the breakpoint.
4. Press F5 (or Debug > Star t Debugging ) to start debugging.
When you start debugging, the application is compiled on the remote target before it starts. Any
compilation errors will appear in the Error List window.
If there are no errors, the app will start and the debugger will pause at the breakpoint.
Now, you can interact with the application in its current state, view variables, and step through code by
pressing command keys such as F10 or F11 .
5. If you want to use the Linux Console to interact with your app, select Debug > Linux Console .
This console will display any console output from the target computer and take input and send it to the
target computer.
You can specify the path to the GDB used by Visual Studio using the GDB Path item in the project's
Debugging property page. This property is available in Visual Studio 2019 version 16.9 and later.
The AttachOptionsForConnection has most of the attributes you might need. The example above shows how
to specify a location to search for more .so libraries. The child element Ser verOptions enables attaching to the
remote process with gdbserver instead. To do that, you need to specify a local gdb client (the one shipped in
Visual Studio 2017 is shown above) and a local copy of the binary with symbols. The SetupCommands
element enables you to pass commands directly to gdb. You can find all the options available in the
LaunchOptions.xsd schema on GitHub.
The drop-down menu for Remote Debug Machine is populated with all established remote connections. To
add a new remote connection, navigate to Tools > Options > Cross Platform > Connection Manager or
search for "Connection Manager" in Quick Launch . You can also specify a new remote deploy directory in the
project's Property Pages (Configuration Proper ties > General > Remote Deploy Director y ).
By default, only the files necessary for the process to debug will be deployed to the remote debug machine. You
can use Solution Explorer to configure which source files will be deployed to the remote debug machine.
When you click on a source file, you'll see a preview of its File Properties directly below the Solution Explorer.
The Content property specifies whether the file will be deployed to the remote debug machine. You can disable
deployment entirely by navigating to Proper ty Pages > Configuration Manager and unchecking Deploy
for the desired configuration.
In some cases, you may require more control over your project's deployment. For example, some files that you
want to deploy might be outside of your solution or you want to customize your remote deploy directory per
file or directory. In these cases, append the following code block(s) to your .vcxproj file and replace
"example.cpp" with the actual file names:
<ItemGroup>
<RemoteDeploy Include="__example.cpp">
<!-- This is the source Linux machine, can be empty if DeploymentType is LocalRemote -->
<SourceMachine>$(RemoteTarget)</SourceMachine>
<TargetMachine>$(RemoteDebuggingTarget)</TargetMachine>
<SourcePath>~/example.cpp</SourcePath>
<TargetPath>~/example.cpp</TargetPath>
<!-- DeploymentType can be LocalRemote, in which case SourceMachine will be empty and SourcePath is a local
file on Windows -->
<DeploymentType>RemoteRemote</DeploymentType>
<!-- Indicates whether the deployment contains executables -->
<Executable>true</Executable>
</RemoteDeploy>
</ItemGroup>
CMake projects
For CMake projects that target a remote Linux machine, you can specify a new remote debug machine in
launch.vs.json. By default, the value of "remoteMachineName" is synchronized with the "remoteMachineName"
property in CMakeSettings.json, which corresponds to your remote build machine. These properties no longer
need to match, and the value of "remoteMachineName" in launch.vs.json will dictate which remote machine is
used for deploy and debug.
IntelliSense will suggest all a list of all established remote connections. You can add a new remote connection by
navigating to Tools > Options > Cross Platform > Connection Manager or searching for "Connection
Manager" in Quick Launch .
If you want complete control over your deployment, you can append the following code block(s) to the
launch.vs.json file. Remember to replace the placeholder values with real values:
"disableDeploy": false,
"deployDirectory": "~\foo",
"deploy" : [
{
"sourceMachine": "127.0.0.1 (username=example1, port=22, authentication=Password)",
"targetMachine": "192.0.0.1 (username=example2, port=22, authentication=Password)",
"sourcePath": "~/example.cpp",
"targetPath": "~/example.cpp",
"executable": "false"
}
]
Next steps
To debug ARM devices on Linux, see this blog post: Debugging an embedded ARM device in Visual Studio.
See also
C++ Debugging Properties (Linux C++)
Linux Project Property Page Reference
11/22/2022 • 2 minutes to read • Edit Online
This section contains reference content for property pages in a Visual C++ Linux project.
General Properties (Linux)
Debugging Properties (Linux)
VC++ Directories Properties (Linux)
Copy Sources Properties (Linux)
C/C++ Properties (Linux)
Linker Properties (Linux)
Build Event Properties (Linux)
Custom Build Step Properties (Linux)
Makefile Project Properties (Linux)
General properties (Linux C++)
11/22/2022 • 2 minutes to read • Edit Online
Output Directory Specifies a relative path to the output file directory. It can
include environment variables.
Target Name Specifies the file name that this project generates.
Target Extension Specifies the file extension (for example, .a ) that this
project generates.
Build Log File Specifies the build log file to write to when build logging is
enabled.
Platform Toolset Specifies the toolset used for building the current
configuration. If not set, the default toolset is used.
WSL *.exe full path Visual Studio 2019 version 16.1 Full path to the
Windows Subsystem for Linux (WSL) executable used to
build and debug.
Remote Build Machine Displays the target machine or device to use for remote
build, deploy, and debug. You can add or edit a target
machine connection by using Tools > Options > Cross
Platform > Connection Manager .
Visual Studio 2019 version 16.1 You can specify a
different machine for debugging on the Debugging page.
Remote Build Root Directory Specifies a path to a directory on the remote machine or
device.
Remote Build Project Directory Specifies a path to a directory on the remote machine or
device for the project.
Remote Deploy Directory Visual Studio 2019 version 16.1 Specifies the directory
path on the remote machine or device to deploy the project.
Enable Incremental Build Visual Studio 2019 version 16.7 Specifies whether to do
incremental builds using the Ninja build system. Builds will
usually be faster for most projects with this setting enabled.
P RO P ERT Y DESC RIP T IO N
Remote Copy Include Directories Visual Studio 2019 version 16.5 A list of directories to
copy recursively from the Linux target. This property affects
the remote header copy for IntelliSense, but not the build. It
can be used when IntelliSense Uses Compiler Defaults
is set to false. Use Additional Include Directories under
the C/C++ General tab to specify additional include
directories to use for both IntelliSense and build.
Remote Copy Exclude Directories Visual Studio 2019 version 16.5 A list of directories not
to copy from the Linux target. Usually, this property is used
to remove subdirectories of the include directories.
IntelliSense Uses Compiler Defaults Visual Studio 2019 version 16.5 Whether to query the
compiler referenced by this project for its default list of
include locations. These locations are automatically added to
the list of remote directories to copy. Only set this property
to false if the compiler doesn't support gcc-like parameters.
Both gcc and clang compilers support queries for the include
directories (for example, g++ -x c++ -E -v -std=c++11 ).
Use of STL Specifies which C++ Standard Library to use for this
configuration, such as: Shared GNU Standard C++
Librar y , or Static GNU Standard C++ Librar y (-static)
C++ Debugging Properties (Linux C++)
11/22/2022 • 2 minutes to read • Edit Online
Remote Debugger Port Number The port number on which the remote
debugger server gdbserver is
listening on the remote system. The
port must not be in use on the remote
system. This value must be positive,
and between 1 and 65535. If not
supplied, a free port number starting
from 4444 is used.
P RO P ERT Y DESC RIP T IO N C H O IC ES
Additional Sources File Path Map Additional path equivalences for the
debugger to use to map Windows
source file names to Linux source file
names. The format is "<windows-
path>=<linux-path>;...". A source file
name found under the Windows path
is referenced as if it's found in the
same relative position under the Linux
path. Files found in the local project
don't require additional mapping.
Include Directories Path to use when searching for include files while building a
VC++ project. Corresponds to environment variable
INCLUDE.
Library Directories Path to use when searching for library files while building a
VC++ project. Corresponds to environment variable LIB.
Source Directories Path to use when searching for source files to use for
IntelliSense.
Copy Sources Specifies whether to copy the sources to the remote system.
Additional Sources To Copy Specifies additional sources to copy to the remote system.
Optionally specify local to remote mapping pairs using a
syntax like this:
fulllocalpath1:=fullremotepath1;fulllocalpath2:=fullremotepat
h2, where a local file can be copied to the specified remote
location on the remote system.
@SourcesToCopyRemotely and @DataFilesToCopyRemotely refer to item groups in the project file. To modify
which sources or data files are copied remotely, edit the vcxproj file like this:
<ItemGroup>
<MyItems Include="foo.txt" />
<MyItems Include="bar.txt" />
<DataFilesToCopyRemotely Include="@(MyItems)" />
</ItemGroup>
C/C++ Properties (Linux C++)
11/22/2022 • 4 minutes to read • Edit Online
General
P RO P ERT Y DESC RIP T IO N C H O IC ES
Debug Information Format Specifies the type of debugging None - Produces no debugging
information generated by the compiler. information, so compilation may be
faster.
Minimal Debug Information -
Generate minimal debug information.
Full Debug Information (DWARF2)
- Generate DWARF2 debug
information.
Warning Level Selects how strict you want the Turn Off All Warnings - Disables all
compiler to be about code errors. Add compiler warnings.
other flags directly to Additional EnableAllWarnings - Enables all
Options . (/w, /Weverything). warnings, including ones disabled by
default.
Optimization
P RO P ERT Y DESC RIP T IO N C H O IC ES
Optimization Specifies the optimization level for the Custom - Custom optimization.
application. Disabled - Disable optimization.
Minimize Size - Optimize for size.
Maximize Speed - Optimize for
speed.
Full Optimization - Expensive
optimizations.
Preprocessor
P RO P ERT Y DESC RIP T IO N
Preprocessor Definitions Defines preprocessing symbols for your source file. (-D)
Undefine Preprocessor Definitions Specifies one or more preprocessor undefines. (-U [macro])
Undefine All Preprocessor Definitions Undefines all previously defined preprocessor values. (-
undef)
Show Includes Generates a list of include files with compiler output. (-H)
Code Generation
P RO P ERT Y DESC RIP T IO N C H O IC ES
Statics are thread safe Emits extra code to use routines No - Disable thread-safe statics.
specified in the C++ ABI for thread- Yes - Enable thread-safe statics.
safe initialization of local statics.
Enable C++ Exceptions Specifies the exception-handling model No - Disable exception handling.
used by the compiler. Yes - Enable exception handling.
Language
P RO P ERT Y DESC RIP T IO N C H O IC ES
Enable Run-Time Type Information Adds code for checking C++ object
types at run time (runtime type
information). (frtti, fno-rtti)
Advanced
P RO P ERT Y DESC RIP T IO N C H O IC ES
General
P RO P ERT Y DESC RIP T IO N C H O IC ES
Report Unresolved Symbol References This option when enabled will report
unresolved symbol references.
Shared Library Search Path Allows the user to populate the shared
library search path. (-rpath-link=path)
Input
P RO P ERT Y DESC RIP T IO N C H O IC ES
Debugging
P RO P ERT Y DESC RIP T IO N C H O IC ES
Advanced
P RO P ERT Y DESC RIP T IO N C H O IC ES
Enable Immediate Function Binding This option marks object for immediate
function binding.
P RO P ERT Y DESC RIP T IO N C H O IC ES
Pre-Build Event
P RO P ERT Y DESC RIP T IO N
Command Line Specifies a command line for the pre-build event tool to run.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy to the remote system.
Optionally specify local to remote mapping pairs using a
syntax like this:
fulllocalpath1:=fullremotepath1;fulllocalpath2:=fullremotepat
h2, where a local file can be copied to the specified remote
location on the remote system.
Pre-Link Event
P RO P ERT Y DESC RIP T IO N
Command Line Specifies a command line for the pre-link event tool to run.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy to the remote system.
Optionally specify local to remote mapping pairs using a
syntax like this:
fulllocalpath1:=fullremotepath1;fulllocalpath2:=fullremotepat
h2, where a local file can be copied to the specified remote
location on the remote system.
Post-Build Event
P RO P ERT Y DESC RIP T IO N
Command Line Specifies a command line for the post-build event tool to
run.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy to the remote system.
Optionally specify local to remote mapping pairs using a
syntax like this:
fulllocalpath1:=fullremotepath1;fulllocalpath2:=fullremotepat
h2, where a local file can be copied to the specified remote
location on the remote system.
Command Line Specifies a command line for the pre-build event tool to run
on the remote system.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy from the remote system.
Optionally specify remote to local mapping pairs using a
syntax like this:
fullremotepath1:=fulllocalpath1;fullremotepath2:=fulllocalpat
h2, where a remote file can be copied to the specified
location on the local machine.
Command Line Specifies a command line for the pre-link event tool to run
on the remote system.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy from the remote system.
Optionally specify remote to local mapping pairs using a
syntax like this:
fullremotepath1:=fulllocalpath1;fullremotepath2:=fulllocalpat
h2, where a remote file can be copied to the specified
location on the local machine.
Command Line Specifies a command line for the post-build event tool to run
on the remote system.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy from the remote system.
Optionally specify remote to local mapping pairs using a
syntax like this:
fullremotepath1:=fulllocalpath1;fullremotepath2:=fulllocalpat
h2, where a remote file can be copied to the specified
location on the local machine.
Custom Build Step Properties (Linux C++)
11/22/2022 • 2 minutes to read • Edit Online
Description A message that's displayed when the custom build step runs.
Outputs The output file that the custom build step generates. This
setting is required so that incremental builds work correctly.
Execute After and Execute Before These options define when the custom build step is run in
the build process, relative to the listed targets. The most
commonly listed targets are BuildGenerateSources,
BuildCompile, and BuildLink, because they represent the
major steps in the build process. Other often-listed targets
are Midl, CLCompile, and Link.
Treat Output As Content This option is only meaningful for Microsoft Store or
Windows Phone apps, which include all content files in the
.appx package.
Makefile Project Properties (Linux C++)
11/22/2022 • 3 minutes to read • Edit Online
General
P RO P ERT Y DESC RIP T IO N C H O IC ES
Configuration Type Specifies the type of output this Dynamic Librar y (.so) - Dynamic
configuration generates. Library (.so)
Static librar y (.a) - Static Library (.a)
Application (.out) - Application
(.out)
Makefile - Makefile
Debugging
See Debugger Properties (Linux C++)
Copy Sources
See Copy Sources Project Properties (Linux C++).
Build Events
Pre -Build Event
P RO P ERT Y DESC RIP T IO N
Command Line Specifies a command line for the pre-build event tool to run.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy to the remote system.
Optionally the list can be provided as a local to remote
mapping pairs using a syntax like this:
fulllocalpath1:=fullremotepath1;fulllocalpath2:=fullremotepat
h2, where a local file can be copied to the specified remote
location on the remote system.
Post-Build Event
P RO P ERT Y DESC RIP T IO N
Command Line Specifies a command line for the post-build event tool to
run.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy to the remote system.
Optionally the list can be provided as a local to remote
mapping pairs using a syntax like this:
fulllocalpath1:=fullremotepath1;fulllocalpath2:=fullremotepat
h2, where a local file can be copied to the specified remote
location on the remote system.
Command Line Specifies a command line for the pre-build event tool to run
on the remote system.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy from the remote system.
Optionally the list can be provided as a remote to local
mapping pairs using a syntax like this:
fullremotepath1:=fulllocalpath1;fullremotepath2:=fulllocalpat
h2, where a remote file can be copied to the specified
location on the local machine.
Command Line Specifies a command line for the post-build event tool to run
on the remote system.
Use In Build Specifies whether this build event is excluded from the build
for the current configuration.
Additional files to copy Specifies additional files to copy from the remote system.
Optionally the list can be provided as a remote to local
mapping pairs using a syntax like this:
fullremotepath1:=fulllocalpath1;fullremotepath2:=fulllocalpat
h2, where a remote file can be copied to the specified
location on the local machine.
C/C++
IntelliSense
The IntelliSense properties can be set at the project or file level to provide clues to the IntelliSense engine. They
do not affect compilation.
Include Search Path Specifies the include search path for resolving included files.
Preprocessor Definitions Specifies the preprocessor defines used by the source files.
Build
P RO P ERT Y DESC RIP T IO N
Build Command Line Specifies the command line to run for the 'Build' command.
Rebuild All Command Line Specifies the command line to run for the 'Rebuild All'
command.
Clean Command Line Specifies the command line to run for the 'Clean' command.
Remote Build
P RO P ERT Y DESC RIP T IO N
Build Command Line Specifies the command line to run for the 'Build' command.
This is executed on the remote system.
P RO P ERT Y DESC RIP T IO N
Rebuild All Command Line Specifies the command line to run for the 'Rebuild All'
command. This is executed on the remote system.
Clean Command Line Specifies the command line to run for the 'Clean' command.
This is executed on the remote system.
Create an archive index Create an archive index (as done by ranlib). This option can
speed up linking and reduce dependency within its own
library.
Create Thin Archive Create a thin archive. A thin archive contains relative paths
to the objects instead of embedding the objects. Switching
between Thin and Normal requires deleting the existing
library.
Verbose Verbose
Output File The /OUT option overrides the default name and location of
the program that the lib creates.
Copy Output Specifies whether to copy the build output file from the
remote system to the local machine.
Create a CMake Linux project in Visual Studio
11/22/2022 • 3 minutes to read • Edit Online
Linux support is available in Visual Studio 2017 and later. To see the documentation for these versions, set the
Version drop-down located above the table of contents to Visual Studio 2017 or Visual Studio 2019 .
We recommend you use CMake for projects that are cross-platform or will be made open-source. You can use
CMake projects to build and debug the same source code on Windows, the Windows Subsystem for Linux
(WSL), and remote systems.
// hello.cpp
#include <iostream>
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project (hello-cmake)
add_executable(hello-cmake hello.cpp)
Next steps
Configure a Linux CMake project
See also
CMake Projects in Visual Studio
Configure a Linux CMake project in Visual Studio
11/22/2022 • 4 minutes to read • Edit Online
Linux support is available in Visual Studio 2017 and later. To see the documentation for these versions, set the
Version drop-down located above the table of contents to Visual Studio 2017 or Visual Studio 2019 .
This topic describes how to add a Linux configuration to a CMake project that targets either a remote Linux
system or Windows Subsystem for Linux (WSL). It continues the series that began with Create a Linux CMake
project in Visual Studio. If you're using MSBuild, instead, see Configure a Linux MSBuild Project in Visual Studio
To change the default CMake settings in Visual Studio 2019 or later, from the main toolbar, open the
Configuration dropdown and choose Manage Configurations .
This command opens the CMake Settings Editor , which you can use to edit the CMakeSettings.json file in
your root project folder. You can also open the file with the JSON editor by clicking the Edit JSON button in the
upper-right of the CMake Settings dialog. For more information, see Customize CMake Settings.
The default Linux-Debug configuration in Visual Studio 2019 version 16.1, and later, looks like this:
{
"configurations": [
{
"name": "Linux-GCC-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"cmakeExecutable": "cmake",
"remoteCopySourcesExclusionList": [ ".vs", ".git", "out" ],
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x64" ],
"remoteMachineName": "${defaultRemoteMachineName}",
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
"remoteCopySources": true,
"rsyncCommandArgs": "-t --delete --delete-excluded",
"remoteCopyBuildOutput": false,
"remoteCopySourcesMethod": "rsync",
"variables": []
}
]
}
In Visual Studio 2019 version 16.6 or later, Ninja is the default generator for configurations targeting a remote
system or WSL, as opposed to Unix Makefiles. For more information, see this post on the C++ Team Blog.
For more information about these settings, see CMakeSettings.json reference.
When you do a build:
If you're targeting a remote system, Visual Studio chooses the first remote system in the list under Tools >
Options > Cross Platform > Connection Manager by default for remote targets.
If no remote connections are found, you're prompted to create one. For more information, see Connect to
your remote Linux computer.
More settings
Use the following settings to run commands on the Linux system before and after building, and before CMake
generation. The values can be any command that is valid on the remote system. The output is piped back to
Visual Studio.
{
"remotePrebuildCommand": "",
"remotePreGenerateCommand": "",
"remotePostbuildCommand": "",
}
Next steps
Configure CMake debugging sessions
See also
Working with project properties
Customize CMake settings
CMake predefined configuration reference
Configure CMake debugging sessions
11/22/2022 • 9 minutes to read • Edit Online
Native CMake support is available in Visual Studio 2017 and later. To see the documentation for these versions,
set the Visual Studio Version selector control for this article to Visual Studio 2017 or later. It's found at the top
of the table of contents on this page.
All executable CMake targets are shown in the Star tup Item dropdown in the toolbar. Select one to start a
debugging session and launch the debugger.
You can also start a debug session from Solution Explorer. First, switch to CMake Targets View in the Solution
Explorer window.
Then, right-click on an executable and select Debug . This command automatically starts debugging the selected
target based on your active configuration.
{
"version": "0.2.1",
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "CMakeHelloWorld.exe (Debug\\CMakeHelloWorld.exe)",
"name": "CMakeHelloWorld.exe (Debug\\CMakeHelloWorld.exe)",
"args": ["${cmake.remoteCopySources}"]
}
]
}
Environment variables defined in CMakeSettings.json can also be used in launch.vs.json using the syntax
${env.VARIABLE_NAME} . In Visual Studio 2019 version 16.4 and later, debug targets are automatically launched
using the environment you specify in CMakeSettings.json. You can unset an environment variable by setting it to
null .
Launch.vs.json reference
There are many launch.vs.json properties to support all your debugging scenarios. The following properties are
common to all debug configurations, both remote and local:
projectTarget: Specifies the CMake target to invoke when building the project. Visual Studio
autopopulates this property if you enter launch.vs.json from the Debug Menu or Targets View . This
value must match the name of an existing debug target listed in the Star tup Item dropdown.
env : Additional environment variables to add using the syntax:
"env": {
"DEBUG_LOGGING_LEVEL": "trace;info",
"ENABLE_TRACING": "true"
}
name : A friendly name to identify the configuration in the Star tup Item dropdown.
project : Specifies the relative path to the project file. Normally, you don't need to change this path when
debugging a CMake project.
projectTarget : Specifies the CMake target to invoke when building the project. Visual Studio autopopulates
this property if you enter launch.vs.json from the Debug Menu or Targets View . This target value must
match the name of an existing debug target listed in the Star tup Item dropdown.
debuggerConfiguration : Indicates which set of debugging default values to use. In Visual Studio 2019 version
16.6, the only valid option is gdb . Visual Studio 2019 version 16.7 or later also supports gdbserver .
args : Command-line arguments passed on startup to the program being debugged.
env : Additional environment variables passed to the program being debugged. For example,
{"DISPLAY": "0.0"} .
processID : Linux process ID to attach to. Only used when attaching to a remote process. For more
information, see Troubleshoot attaching to processes using GDB.
Additional options for the gdb configuration
program : Defaults to "${debugInfo.fullTargetPath}" . The Unix path to the application to debug. Only
required if different than the target executable in the build or deploy location.
remoteMachineName : Defaults to "${debugInfo.remoteMachineName}" . Name of the remote system that hosts the
program to debug. Only required if different than the build system. Must have an existing entry in the
Connection Manager. Press Ctrl+Space to view a list of all existing remote connections.
cwd : Defaults to "${debugInfo.defaultWorkingDirectory}" . The Unix path to the directory on the remote
system where program is run. The directory must exist.
gdbpath : Defaults to /usr/bin/gdb . Full Unix path to the gdb used to debug. Only required if using a
custom version of gdb .
preDebugCommand : A Linux command to run immediately before invoking gdb . gdb doesn't start until the
command completes. You can use the option to run a script before the execution of gdb .
Additional options allowed with the gdbserver configuration (16.7 or later)
program: Defaults to "${debugInfo.fullTargetPath}" . The Unix path to the application to debug. Only
required if different than the target executable in the build or deploy location.
TIP
Deploy is not yet supported for local cross-compilation scenarios. If you are cross-compiling on Windows (for
example, using a cross-compiler on Windows to build a Linux ARM executable) then you'll need to manually copy
the binary to the location specified by program on the remote ARM machine before debugging.
The following options can be used when debugging on a remote system or WSL using the cppdbg
configuration type. In Visual Studio 2019 version 16.6 or later, configuration type cppgdb is recommended.
name : A friendly name to identify the configuration in the Star tup Item dropdown.
: Specifies the relative path to the project file. Normally, you don't need to change this value
project
when debugging a CMake project.
projectTarget: Specifies the CMake target to invoke when building the project. Visual Studio
autopopulates this property if you enter launch.vs.json from the Debug Menu or Targets View . This
value must match the name of an existing debug target listed in the Star tup Item dropdown.
args : Command-line arguments passed on startup to the program being debugged.
processID: Linux process ID to attach to. Only used when attaching to a remote process. For more
information, see Troubleshoot attaching to processes using GDB.
program: Defaults to "${debugInfo.fullTargetPath}" . The Unix path to the application to debug. Only
required if different than the target executable in the build or deploy location.
remoteMachineName: Defaults to "${debugInfo.remoteMachineName}" . Name of the remote system that hosts
the program to debug. Only required if different than the build system. Must have an existing entry in the
Connection Manager. Press Ctrl+Space to view a list of all existing remote connections.
cwd : Defaults to "${debugInfo.defaultWorkingDirectory}" . Full Unix path to the directory on the remote
system where program is run. The directory must exist.
environment : Additional environment variables passed to the program being debugged. For example,
"environment": [
{
"name": "ENV1",
"value": "envvalue1"
},
{
"name": "ENV2",
"value": "envvalue2"
}
]
pipeArgs : An array of command-line arguments passed to the pipe program to configure the connection.
The pipe program is used to relay standard input/output between Visual Studio and gdb . Most of this
array doesn't need to be customized when debugging CMake projects. The exception is the
${debuggerCommand} , which launches gdb on the remote system. It can be modified to:
Export the value of the environment variable DISPLAY on your Linux system. In the following
example, this value is :1 .
"pipeArgs": [
"/s",
"${debugInfo.remoteMachineId}",
"/p",
"${debugInfo.parentProcessId}",
"/c",
"export DISPLAY=:1;${debuggerCommand}",
"--tty=${debugInfo.tty}"
],
Run a script before the execution of gdb . Ensure execute permissions are set on your script.
"pipeArgs": [
"/s",
"${debugInfo.remoteMachineId}",
"/p",
"${debugInfo.parentProcessId}",
"/c",
"/path/to/script.sh;${debuggerCommand}",
"--tty=${debugInfo.tty}"
],
stopOnEntry : A boolean that specifies whether to break as soon as the process is launched. The default is
false.
visualizerFile : A .natvis file to use when debugging this process. This option is incompatible with gdb
pretty printing. Also set showDisplayString when you set this property.
showDisplayString : A boolean that enables the display string when a visualizerFile is specified. Setting
this option to true can cause slower performance during debugging.
setupCommands : One or more gdb command(s) to execute, to set up the underlying debugger.
miDebuggerPath : The full path to gdb . When unspecified, Visual Studio searches PATH first for the
debugger.
Finally, all of the deployment options defined for the cppgdb configuration type can be used by the
cppdbg configuration type as well.
You can configure the cppdbg configuration to debug using gdbserver . You can find more details and a sample
launch configuration in the Microsoft C++ Team Blog post Debugging Linux CMake Projects with gdbserver .
See also
CMake projects in Visual Studio
Configure a Linux CMake project
Connect to your remote Linux computer
Customize CMake build settings
Configure CMake debugging sessions
Deploy, run, and debug your Linux project
CMake predefined configuration reference
Tutorial: Create C++ cross-platform projects in
Visual Studio
11/22/2022 • 10 minutes to read • Edit Online
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.txt file, Visual
Studio configures the IntelliSense and build settings automatically. You can quickly start editing, building, and
debugging your code locally on Windows. Then, switch your configuration to do the same on Linux, all from
within Visual Studio.
In this tutorial, you learn how to:
clone an open-source CMake project from GitHub
open the project in Visual Studio
build and debug an executable target on Windows
add a connection to a Linux machine
build and debug the same target on Linux
Prerequisites
Set up Visual Studio for Cross Platform C++ Development
First, install Visual Studio and choose the Desktop development with C++ and Linux
development with C++ workloads . This minimal install is only 3 GB. Depending on your
download speed, installation shouldn't take more than 10 minutes.
Set up a Linux machine for Cross Platform C++ Development
Visual Studio doesn't require any specific distribution of Linux. The OS can be running on a
physical machine, in a VM, or in the cloud. You could also use the Windows Subsystem for Linux
(WSL). However, for this tutorial a graphical environment is required. WSL isn't recommended
here, because it's intended primarily for command-line operations.
Visual Studio requires these tools on the Linux machine: C++ compilers, gdb, ssh, rsync, make, and
zip. On Debian-based systems, you can use this command to install these dependencies:
Visual Studio requires a recent version of CMake on the Linux machine that has server mode
enabled (at least 3.8). Microsoft produces a universal build of CMake that you can install on any
Linux distro. We recommend you use this build to ensure that you have the latest features. You can
get the CMake binaries from the Microsoft fork of the CMake repo on GitHub. Go to that page and
download the version that matches the system architecture on your Linux machine, then mark it as
an executable:
You can see the options for running the script with --help . We recommend that you use the
-prefix option to specify installing in the /usr path, because /usr/bin is the default location
where Visual Studio looks for CMake. The following example shows the Linux-x86_64 script.
Change it as needed if you're using a different target platform.
1. On the Visual Studio main menu, choose File > Open > CMake . Navigate to the CMakeLists.txt file in
the root of the bullet3 repo you just downloaded.
As soon as you open the folder, your folder structure becomes visible in the Solution Explorer .
This view shows you exactly what is on disk, not a logical or filtered view. By default, it doesn't show
hidden files.
2. Choose the Show all files button to see all the files in the folder.
After this operation completes, IntelliSense is configured. You can build the project, and debug the
application. Visual Studio now shows a logical view of the solution, based on the targets specified in the
CMakeLists files.
2. Use the Solutions and Folders button in the Solution Explorer to switch to CMake Targets View.
Here is what that view looks like for the Bullet SDK:
Targets view provides a more intuitive view of what is in this source base. You can see some targets are
libraries and others are executables.
3. Expand a node in CMake Targets View to see its source code files, wherever those files might be located
on disk.
The CMake Settings Editor opens. Select the green plus sign on the left-hand side of the editor to add a
new configuration. The Add Configuration to CMakeSettings dialog appears.
This dialog shows all the configurations included with Visual Studio, plus any custom configurations that
you create. If you want to continue to use a x64-Debug configuration, that should be the first one you
add. Select x64-Debug , and then choose the Select button. Visual Studio creates the CMakeSettings.json
file with a configuration for x64-Debug , and saves it to disk. You can use whatever names you like for
your configurations by changing the name parameter directly in CMakeSettings.json.
6. Choose the launch button to build the application and necessary dependencies, then launch it with the
Visual Studio debugger attached. After a few moments, the running application appears:
7. Move your mouse into the application window, then click a button to trigger the breakpoint. The
breakpoint brings Visual Studio back to the foreground, and the editor shows the line where execution is
paused. You can inspect the application variables, objects, threads, and memory, or step through your
code interactively. Choose Continue to let the application resume, and then exit it normally. Or, halt
execution within Visual Studio by using the stop button.
If it's the first time you're connecting to a Linux system, the Connect to Remote System dialog appears.
If you've already added a remote connection, you can open this window by navigating to Tools >
Options > Cross Platform > Connection Manager .
4. Provide the connection information to your Linux machine and choose Connect . Visual Studio adds that
machine as to CMakeSettings.json as your default connection for Linux-Debug . It also pulls down the
headers from your remote machine, so you get IntelliSense specific to that remote connection. Next,
Visual Studio sends your files to the remote machine and generates the CMake cache on the remote
system. These steps may take some time, depending on the speed of your network and power of your
remote machine. You'll know it's complete when the message "Target info extraction done" appears in the
CMake output window.
Set a breakpoint, build, and run on Linux
Because it's a desktop application, you need to provide some additional configuration information to the debug
configuration.
1. In the CMake Targets view, right-click AppBasicExampleGui and choose Debug and Launch Settings to
open the launch.vs.json file that's in the hidden .vs subfolder. This file is local to your development
environment. You can move it into the root of your project if you wish to check it in and save it with your
team. In this file, a configuration has been added for AppBasicExampleGui. These default settings work in
most cases, but not here. Because it's a desktop application, you need to provide some additional
information to launch the program so you can see it on your Linux machine.
2. To find the value of the environment variable DISPLAY on your Linux machine, run this command:
echo $DISPLAY
In the configuration for AppBasicExampleGui, there's a parameter array, "pipeArgs". It contains a line:
"${debuggerCommand}". It's the command that launches gdb on the remote machine. Visual Studio must
export the display into this context before that command runs. For example, if the value of your display is
:1 , modify that line as follows:
"export DISPLAY=:1;${debuggerCommand}",
3. Launch and debug your application. Open the Select Star tup Item drop-down in the toolbar and
choose AppBasicExampleGui . Next, either choose the green play icon in the toolbar, or press F5 . The
application and its dependencies are built on the remote Linux machine, then launched with the Visual
Studio debugger attached. On your remote Linux machine, you should see an application window appear.
4. Move your mouse into the application window, and click a button. The breakpoint is hit. Program
execution pauses, Visual Studio comes back to the foreground, and you see your breakpoint. You should
also see a Linux Console Window appear in Visual Studio. The window provides output from the remote
Linux machine, and it can also accept input for stdin . Like any Visual Studio window, you can dock it
where you prefer to see it. Its position is persisted in future sessions.
5. You can inspect the application variables, objects, threads, memory, and step through your code
interactively using Visual Studio. But this time, you're doing it all on a remote Linux machine instead of
your local Windows environment. You can choose Continue to let the application resume and exit
normally, or you can choose the stop button, just as with local execution.
6. Look at the Call Stack window and view the Calls to x11OpenGLWindow since Visual Studio launched the
application on Linux.
What you learned
In this tutorial, you cloned a code base directly from GitHub. You built, ran, and debugged it on Windows without
modifications. Then you used the same code base, with minor configuration changes, to build, run, and debug
on a remote Linux machine.
Next steps
Learn more about configuring and debugging CMake projects in Visual Studio:
CMake Projects in Visual Studio
In Visual Studio 2019 version 16.1, AddressSanitizer (ASan) support is integrated into Linux projects. You can
enable ASan for both MSBuild-based Linux projects and CMake projects. It works on remote Linux systems and
on Windows Subsystem for Linux (WSL).
About ASan
ASan is a runtime memory error detector for C/C++ that catches the following errors:
Use after free (dangling pointer reference)
Heap buffer overflow
Stack buffer overflow
Use after return
Use after scope
Initialization order bugs
When ASan detects an error, it stops execution immediately. If you run an ASan-enabled program in the
debugger, you see a message that describes the type of error, the memory address, and the location in the
source file where the error occurred:
You can also view the full ASan output (including where the corrupted memory was allocated/deallocated) in the
Debug pane of the output window.
To enable ASan for MSBuild-based Linux projects, right-click on the project in Solution Explorer and select
Proper ties . Next, navigate to Configuration Proper ties > C/C++ > Sanitizers . ASan is enabled via
compiler and linker flags, and requires your project to be recompiled to work.
You can pass optional ASan runtime flags by navigating to Configuration Proper ties > Debugging >
AddressSanitizer Runtime Flags . Click the down-arrow to add or remove flags.
To enable ASan for CMake, right-click on the CMakeLists.txt file in Solution Explorer and choose CMake
Settings for Project .
Make sure you have a Linux configuration (for example, Linux-Debug ) selected in the left pane of the dialog:
The ASan options are under General . Enter the ASan runtime flags in the format "flag=value", separated by
spaces. The UI incorrectly suggests using semi-colons. Use spaces or colons to separate flags.
A SA N VERSIO N GC C VERSIO N
libasan0 gcc-4.8
libasan2 gcc-5
libasan3 gcc-6
libasan4 gcc-7
libasan5 gcc-8
You can determine which version of GCC you have by using this command:
gcc --version
To view the version of libasan-dbg you need, run your program, and then look at the Debug pane of the
Output window. The version of ASan that's loaded corresponds to the version of libasan-dbg needed on your
Linux machine. You can use Ctrl + F to search for "libasan" in the window. If you have libasan4, for example, you
see a line like this:
You can install the ASan debug bits on Linux distros that use apt with the following command. This command
installs version 4:
Full instructions for installing debug symbol packages on Ubuntu can be found at Debug symbol packages.
If ASan is enabled, Visual Studio prompts you at the top of the Debug pane of the Output window to install the
ASan debug symbols.