articles » current » information-technology » linux » setup-and-configure » visual-c-plus-plus-2022

MS VC++ 2022 on Linux

Develop Microsoft Visual C++ 2022 or Visual Studio 2022 projects for Linux

This focuses mainly on the development of Linux server apps. This article is based on Microsoft's docs.

See also: Build and run Blazor WASM projects on Linux

Visual Studio 2022

  1. Open Visual Studio 2022 and choose to create a new project. Search for Linux projects and choose Console Application with the "hello" example.

  2. Choose your project's architecture.

  3. Update the repository on the Linux machine.

    On Ubuntu, issue this command:

    sudo apt-get update

    On Fedora/CentOS, be logged in as user root and issue this command:

    yum update
  4. Install prerequisite packages on the Linux machine: openssh server, g++, gdb and gdb server

    On Ubuntu, issue this command:

    sudo apt-get install openssh-server g++ gdb gdbserver make ninja-build rsync zip

    On Fedora/CentOS, be logged in as user root and issue this command:

    yum install openssh-server g++ gdb gdb-gdbserver ninja-build make rsync zip
  5. Hit the F5 key and the project will try to connect to a remote system. Enter the host machine's IP address, user name and password.

  6. To add another connection/remote machine, go to Tools > Options and search for Connection Manager.

  7. To change the connection/remote machine the project is using, go to the project's properties and change Remote Build Machine.

  8. Choose the project's configuration type: Dynamic Library, Static Library or Application (in this example, Application).

  9. Add additional library dependencies on the Linker > Input property page.

  10. Pass additional pre-launch commands to the debugger to do things like launch graphical apps on the remote linux machine by specifying export DISPLAY=:0.0

  11. Hitting the F5 key should run the application on the host machine and show the output in the Linux Console Window (at the bottom of the screen - if not visible, select the menu options Debug > Linux Console). Also, breakpoints can be set for the debugger in Visual Studio 2022.

Some Notes on Connecting to and Developing with Windows Subsystem for Linux (WSL)

Because Windows uses port 22 for its own SSH implementation, change the SSH port on the WSL machine to another one such as 23. To do this, edit the /etc/ssh/sshd_config file. Change to Port 23 and PasswordAuthentication yes to work with Visual Studio's Connection Manager.

sudo nano /etc/ssh/sshd_config
sudo systemctl enable ssh
sudo ssh-keygen -A
sudo service ssh restart

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.