Cross-platform (Linux) development based on VS2019 C++ - introduction

I. Introduction

First declare that my server is Ubuntu 16.04. As you can see from the title, my development tool uses Visual Studio 2019, and C++ language is used to realize cross-platform development of windows-linux.

2. About cross-platform

1. What is cross-platform?

According to Baidu Encyclopedia, the concept of cross-platform is an important concept in software development, that is , it does not depend on the operating system and does not depend on the hardware environment. An application developed under one operating system can still run under another operating system.

Cross-platform is defined as a programming language, software or hardware device that can run on computers with multiple operating systems or different hardware architectures.
To put it simply, the cross-platform of this article is a code that can be compiled and run on Windows, and can also be compiled and run on Linux. This code is said to be cross-platform.

2. Features

  • The same code, no need to change
  • same result

3. Requirements for cross-platform code

① Try to use standard functions, types, syntax, etc.

For example, ANSI C/STL is a function supported by each platform;

char/short/int/double/float, these types are supported by all platforms.

②Try to avoid ambiguity in platform-related types, functions, and syntax

For example, some compilers think that the variable i is repeatedly defined as follows

for(int i = 0; i < 3; i++){}

for(int i = 0; i < 6; i++){}

4. Cross-platform development

As we all know, in the past, breakpoints were basically used for debugging. In which line the breakpoint in VS2019 is hit, that line does not run, which means that return is not executed, the whole program does not end, and the result printed by cout can be printed. In the past, I usually opened an application program under my own operating system, and compiled the code to run it by myself after writing the code (local mode).

After entering the cross-platform development, after running, the project is generated under the ubuntu system. Here is an explanation, that is, there are only .cpp files in the working directory of vs on windows, and there is no compiled and generated things; enter the ubuntu system with root privileges , open the projects folder of home and you will find the project files generated by compiling and running (including cpp and bin (executable) folders, as shown in the following figure)

So the real operation is to use the ubuntu system to run, that is, to achieve cross-platform development. Simply put, cross-platform development is to send the code from VS2019 of windows to ubuntu, and use c/c++ syntax to compile and generate in ubuntu. If there is an error in compilation or something abnormal, the error message is sent to windows with the help of signals . displayed on the VS2019 console.

The above debugging mode is also called gdb, and it uses the way of breakpoints, not the way of real operation. If you want the real operation, you need to enter the Debug folder of the project file in ubuntu, open the terminal and enter the command ./Project1.out to run, so as to achieve the real operation.

The above is a detailed introduction to cross-platform development and gdb mode.

3. Learn cross-platform development in stages

Regarding the cross-platform (Linux) development of VS2019 C++, it will continue to be updated later. It is roughly divided into three stages. The goals and contents are as follows

1, linux kernel programming - the first stage

Learn kernel functions and lay the foundation

2. Network Foundation - Phase 2

Core, difficult points, especially IO multiplexing, socket encapsulation, thread encapsulation

3. Image processing - the third stage (buffering)

Relatively easy and fun, Qt combined with OpenCV image processing, must use Qt ui to save project time

Next, we enter the learning of cross-platform development: first, build the environment

Cross-platform (Linux) development based on VS2019 C++ (1.1) - environment construction


 

Guess you like

Origin blog.csdn.net/hml111666/article/details/123416678