Use VS to remotely connect to linux and develop

This function requires vs2015 and above , here is VS2019 as an example

When installing VS, you need to select linux support. If you have already installed it, you can install it by modifying VS.
insert image description here

specific process:

First, create a new project
insert image description here
, select the Linux console application,
insert image description here
select the location and name, and then create
insert image description here
it. In this way, our project will create a main file with the content:

#include <cstdio>

int main()
{
    
    
    printf("%s 向你问好!\n", "ThreadPool");
    return 0;
}

Click here to add a remote connection
insert image description here
. Note that linux needs to have ssh service, just fill in normally.
insert image description here
I am connected to Alibaba Cloud here. Note that you need to obtain Alibaba Cloud’s external network ip , so that you can connect smoothly.

Note: The remote connected linux should have gdb, if not, use the package manager to install (apt-get under Ubuntu, yum under CentenOS) to
download and install:

sudo apt-get install gdb

Next, you need to make some settings for this connection.
Tools->Options must be ticked, and then click Update (download for the first time), so that you can write codes to have intelligent prompts. Then you will download and
insert image description here
update the header and wait for it to complete. Then you can
insert image description here
check the properties window.
There are a bunch of settings in it, which can be set as needed . You can
insert image description here
see the remote root directory .
insert image description here

Try to run this project.
Let’s run this project after setting a breakpoint. insert image description here
You can see that the running results have been displayed. Spicy~

View the written program on the linux side.
Our remote root directory is ~/projects.
Let's go to this location to check.
insert image description here
This is our project, and then proceed to another layer.
insert image description here

You can see the main.cpp file. bin is the directory of the executable program, and obj is the cache file.

After that, you can freely use VS to (remotely) write linux programs~

Guess you like

Origin blog.csdn.net/weixin_43003108/article/details/121099986