Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use VS2022 to develop C++ programs for online remote compilation and deployment

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use VS2022 to develop online remote compilation and deployment of C++ programs", in daily operation, I believe many people in how to use VS2022 to develop online remote compilation and deployment of C++ programs on the question there are doubts, small series consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "how to use VS2022 to develop online remote compilation deployment of C++ programs" doubts help! Next, please follow the small series to learn together!

First, let's start with a bit of C++ resource sharing, meaning something.

1, c++ class library source code and other related resources.

C++ Reference Manual. The page is a bit retro, but there is a Chinese version.

3. GUNC++ library, you know.

4. Some Chinese open source resources shared by a group of big shots.

Second, the next is the transition, to say something irrelevant, purely complaining, you can skip directly to see the third section.

C/C++ I haven't played for about five or six years, and I basically forgot about it. The main thing is to enter the pit of C#(two + signs more than C++). Just a few days ago in the annual leave, today (2021-12-15) a little boring, so in the afternoon I thought about C++, try to feel, but a long time ago VisualC++6.0 this ancient compiler is certainly not suitable, so the first thought of VisualStudioCode. So download MinGW first, download address is: sourceforge.net/projects/mingw/

5. After installing MinGW, check all the following. If you encounter an option that you don't know what it is, it is generally checked by default to reduce the probability of error.

6. After MinGW is installed, you need to add the bin directory under the installation root directory to the Path of the environment variable, so that the console or PowerShell can be compiled directly using the gcc or g++ command (using the compiler to run directly is also possible, but writing commands feels a bit more glamorous).

Cmd command line input gcc-v or g++-v can display version information those, it is OK.

7, and then VSCODE installed above the C++ language environment, I installed the following circled those.

8, and then the bottom of the installation, you can configure the run button. However, I did not configure it properly locally, so I used the triangle in the upper right corner of VSCODE to run.

9, as follows, click both to compile and run. If there are multiple file paths, you need to configure them to link them together.

10. It also supports compilation using commands in the terminal window. After compilation, the a.exe file will be generated by default. If you need to generate a file with a specified name, you can use the name specified by g++ xxx.cpp to achieve it.

After the above steps, I always feel a little strange, maybe VSCODE I prefer to use to develop something such as golang, or front-end, etc. Development C++ always feel not very good, also do not know how to cross-platform release (limited strength, do not know). So I finally switched to Visual Studio 2022, the strongest IDE in the universe, for cross-platform development.

Third, the following is the beginning of the text, using VS2022 to develop remote cross-platform C++ programs.

11. First of all, I applied for a TX Cloud Virtual Machine (CentOS8.0 system) before, which came in handy. Let's go over there and drop something off. The command for the remote linux console is ssh username @ip address

12, remote past, you need to install sshserver. Command: yuminstall-ysslopenssh-server. It is installed so that it can be accessed remotely by the VS2022 compiler.

13. Go to the ssh configuration file and make some modifications. Modify file: /etc/ssh/sshd_config

Change some information, turn on the PermitRootLogin, RSAAuthentication, PubkeyAuthentication comments and set them to yes. If you can't find the corresponding one, you can also add it directly.

15. Start the sshd service and set it to boot. The orders were:

systemctlstartsshd.service

systemctlenablesshd.service

Then install the gdb service. Installation command: yum-yinstallgdbgdb-gdbserver

Gdb is a common debugger under linux, not installed may lead to compilation failure or unable to compile.

17, and then install g++ tools, first check whether g++ is installed. Some linux systems may come with gcc and g++, if they don't, we'll install them ourselves.

Install gcc and g++ by command. Installation command:

sudoyum-yinstallgccgcc-c++kernel-devel

After installation, check the g++ version. The version number is displayed to indicate successful installation, similar to MinGW installed on Windows. However, the version here is 4.x, which seems to be a bit older than the version above win, but it does not affect it temporarily. If it does not apply to the new features of C++, it should not be a problem. If you need to use some new features, you need to install a higher version of the g++ tool independently, and the big guys can study it themselves.

20. Let's do an experiment. First of all, we need to make a little configuration for VS2022. Configure something that provides remote access. Tools-Options-Cross Platform-Add a remote access connection to the Connection Manager.

hostname =ip address; port default 22

21, after the completion of the setting. You can start writing code tests. Start by creating a C++ project using VS2022. Here I am using the console project.

22, some configuration, in the project right-click properties inside, you can see that the remote connection address of the configuration has been added. And in the remote root directory, set a folder, called cpp_projects, after setting, compiled code and files will be thrown into this folder.

23. Where the program is executed, the IP address of the remote Linux server configured above will also appear by default.

24, the execution of the program, because there is no power failure or other interrupt operation, so the successful execution of the future, it will directly change back to the way it has not started. But at this point, after running (after compilation), you will find that the folder just configured does appear in the root directory. We can run the program directly in the corresponding debug, and print out the print content we developed above VS2022.

25. Add the header file to try the effect, and throw the header information into hello.h.

At the same time, a console input was added to test the input and output it through the pointer. Then run the program. If it runs successfully, it will display the word deployment success, but it will flash and be easy to ignore.

27, remote linux system above, try the effect.

28. Take a look at the intermediate file generated by compilation. The xxx.o file under the Obj folder seems to be a bit embarrassing. If it is garbled, it will not be popular science. The big guys will play by themselves.

Similarly, on Linux systems, you can also use the g++ command to compile. Because the code is automatically copied remotely, it can also be compiled and run directly on top of it.

30, the above code with input statements, so the console will be interrupted to stay, at this moment you can also see the output of the remote call Linux console window above VS. However, as soon as the interrupt was gone, the program would immediately finish executing.

At this point, the study on "how to use VS2022 to develop online remote compilation and deployment of C++ programs" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report