In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to use VS2019 for Linux remote development". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
A brief introduction to the cross-platform development functions of Visual Studio
Since Visual Studio 2017, Microsoft has launched the cross-platform development function of VS, which allows you to edit the code in VS, then compile and debug it remotely, automating the work we need to do manually, and greatly reducing our burden. The supported platforms include Android and Linux, the protagonists we are going to focus on today.
You may wonder how VS is developed remotely, although you don't need to know this knowledge to develop, but I would like to give a brief explanation in two minutes.
VS for remote development is divided into two steps:
Create a connection to the remote environment, and then let vs synchronize the system header files in the remote environment to the local (you can also specify a header file somewhere else, which will be explained later). The code completion of C++ only needs the header file.
When the code is written, select the appropriate remote environment, vs copies the target file and code to the specified location in the remote environment, and then compiles according to your configuration.
Vs will then run your program in console's gdb or gdbserver, during which you can fully enjoy the efficiency and convenience of vs debugger.
After the above steps, you can debug your own cross-platform programs in vs.
Remote development of Linux with VS 2019
This is the end of the introduction, let's take a look at the graphic tutorials for Linux development in VS 2019. Before we begin, we need to do some preparatory work:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
VS 2019 is installed and C++ for Linux function is checked
Prepare an available Linux remote environment, such as a Linux virtual machine with static IP configured, and the GCC toolchain and openssh have been installed.
When we're ready, we should get down to business.
Create a project
After installing the C++ for Linux feature, we will see the options for Linux in the panel where the new project is created, as shown in the figure:
Here we chose a blank console program built using a traditional vs project solution, and you can see how to create a cmake project in a subsequent article, not to mention here.
There is nothing to say below. Select the storage location of the project, note that it is the local location, and the location of the remote machine will be configured later:
Click create, and our remote development project will be created successfully.
Configure remote projects
VS cannot edit the configuration of an empty project, so we first create a main.cpp in the project, then click on the top menu: project-> Properties, and you can see the configuration interface of the project:
The remote computer is added in the remote connection manager under debugging. There is generally no need to change here, unless you need to change the type of project or where the compiled results are stored. If you have more than one remote environment, you can also choose here.
Debug section provides gdb and gdbserver, the former is to let VS start a console on Linux, then run gdb in it and return the output. If the terminal on your Linux is configured with color output, then the vs does not know them and will be displayed as the original string.
When using gdbserver, gdbserver local VS parsing returned data is remotely enabled without murmur.
Here we choose gdbserver. If you find that you can't break the point, refer to Microsoft's suggestion and switch back to the gdb solution:
Next is the focus of configuration, the first is to configure the header files of the remote environment that need to be synchronized, with these files vs can automatically complete and prompt your code:
The default copy path usually already contains most of the header files on the Linux, and usually we don't need to change it. The synchronization of the header file occurs after the project is successfully built for * * times or manually after adding a remote connection.
Next, there is the choice of the Cpicket + compiler, that is, the configuration of the gcc and Gmail + compilation parameters. Explaining these parameters is beyond the scope of our discussion. We only need to choose the appropriate standard version of C++ here:
Here we chose caterpillar 17. The other settings are the same as when developing on Windows, and vs can be automatically converted to the parameters of glossy +, so I won't repeat them here.
Add remote environment
With the remote environment, we can synchronize the header files or debug and run.
Vs automatically allows you to connect to the remote environment when you compile or debug your project * *. Of course, we recommend setting it in debugging-> options-> Cross-platform-> connection Manager:
Enter your remote ip/ domain name. Port ssh is 22 by default. For security reasons, you need to modify it to another port. This is convenient to demonstrate the use of the default configuration. The password is the same as above. You should consider logging in with a more secure ssh private key.
After the login is successful, the connection is added, and we see that there is also a remote header manager setting item under the manager, which is used to synchronize the header file:
Clicking the update button will start synchronizing header files, which will be cached locally, because it may take a long time to copy a large number of files remotely at once.
In this way, the remote environment is added and you can start writing code.
Local writing and remote debugging
At this point, you can write code for the Linux platform in VS, and automatic completion will work:
You can see that the header files and structures in Linux are already recognizable. If you find that you can't automatically complete (usually after adding a remote connection or after the project settings have changed), try closing vs and reopening it, and if it doesn't work, try refreshing intellisense or resynchronizing the header file.
After editing, we can click the debug button to run our program:
Note that the architecture built must be consistent with the remote environment, for example, the remote environment is x64, where you can choose x64 or x86, but not arm, otherwise an error will be reported.
This is the test code that outputs the current version of the Linux system kernel:
# include # include # include int main () {auto start = chrono::high_resolution_clock::now (); utsname names; if (uname (& names)! = 0) {std::perror ("cannot get unames");} std::cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.