[Linux Network Programming] Cross-platform development of Linux + VS2019 environment configuration (Ubantu16.04)

Table of contents

foreword

1. Ubuntu configuration

Two, Linux installation remote debugging

Linux setting remote debugging ssh allows root login

Test host and virtual machine connections

3. Visual Studio 2019 installation

installation steps 

create new project

Configure the connector

Write and debug the running program


foreword

This article mainly learns Linux kernel programming , combined with Visual Studio 2019 for cross-platform programming, including Linux + Visual Studio2019 environment configuration (Ubantu16.04) related operations

1. Ubuntu configuration

Step1:

Confirm whether the system version is Ubuntu16.04

PS: Note here, it is not the version of the virtual machine VMware!

Step2:

Modify the login authority of the root user of the Ubantu system and set the root password. The command line is as follows:

sudo passwd root

Test whether you can enter the root user. If # appears, it means that the password of the root user has been set successfully. The command line is as follows:

su root

Step3:

User login can be selected when setting login

Go to the /usr/share/lightdm/lightdm.conf.d/ directory

Open the 50-unity-greeter.conf file, the command line is as follows:

gedit 50-unity-greeter.conf

Add the following information to the open file

user-session=ubuntu
greeter-show-manual-login=true
all-guest=false

As shown below: 

Step4:

Restart the system, and the input user name information will appear, as shown in the figure below:

You can see the edit box for entering the account number, enter the account root, and enter the password after entering, the password is the password entered in step 2 just now

The desktop will appear, an error was found when reading /root/.profile, and the dialog box is shown in the figure below:

 

Click the OK button to enter the system, use the gedit /root/.profile command to modify the file, and find mesg n

Change to: tty -s && mesg n, as shown in the figure below:

tty -s && mesg n

Before modification, as shown in the figure below:

 After modification, as shown in the figure below:

Click Save in the upper right corner of the window, close the window to exit, and then restart the system again

Two, Linux installation remote debugging

PS: At this time, the Linux host must install the remote debugging service, and the installation is as follows:

sudo apt-get install openssh-server g++ gdb gdbserver

Linux setting remote debugging ssh allows root login

PS: By default, the ssh service is installed and enabled, and root is not allowed to log in, so the following steps must be completed

After installing ssh, find the ssh configuration file /etc/ssh/sshd_config

Use the terminal command gedit /etc/ssh/sshd_config command to modify the file

Find the configuration item PermitRootLoginwithout-password

Add a # on the far left to comment this line and write PermitRootLogin yes

PermitRootLogin yes

As shown below:

Test host and virtual machine connections

Enter the command ifconfig in the Ubuntu terminal to view the IP address of the Ubuntu virtual machine

Enter the command ipconfig on the win10 (or win11) CMD command line to view the host ip address

PS: The demonstration situation is that VMware uses NAT mode 

The following is recorded here, as shown in the figure, our virtual machine ip: 192.168. 48 .128 host ip: 192.168. 48 .1 

Both are in the 48 network segment, and the same network segment is the correct IP

When the virtual machine is turned on, test the ping connection of the Ubuntu system, and command the ping host ip in the command line of the window system

PS: If the situation shown in the above two pictures does not appear, it means that the connection is not connected. Usually, the firewall under the window system blocks the ping connection. Just turn off the window firewall

Here, Linux pings the host, and the host pings Linux are all successful! 

3. Visual Studio  2019 installation

installation steps 

Step 1:

Double-click to run the executable program exe to install, here is the decompression of the installation file and wait for a while

Step 2:

After waiting for a period of time, enter the system and installation file verification interface, click Continue, and continue to wait

 

Step 3:

After waiting for a period of time, it will automatically enter the installation interface

The part in the red box is the installation drive letter path selection, which can be customized, but remember that no Chinese characters, including Chinese symbols, can appear in the path. You need to select the plug-in part to be installed during installation. The plug-ins to be installed are listed in the following figure. , check all the following plug-ins that need to be installed

Step 4:

Set the path and plug-in and click Install to enter the following interface. Here is the time that can be consumed depending on the performance of the personal computer. My computer takes about 20 minutes. During the installation process, it needs to be connected to the Internet. After the installation, it will Prompted to restart the computer, and then we click "Restart now"

This completes the installation of vs2019! We continue to configure our cross-platform environment

create new project

Select language C++: 

Select platform Linux:

We can choose an empty project or generate the default console hello program, here we choose an empty project: 

 Then enter the project name to create:

Configure the connector

When using VS to write a Linux program for the first time, we need to configure the connector: click Tools - Options

Click Cross-Platform - Connection Manager - Add

Enter the command ifconfig in the Ubuntu terminal to view the IP address of the Ubuntu virtual machine

Then we enter the Linux host ip, user name root, password and other information to connect:

After the installation is complete, you can connect successfully

PS: As long as the SSH service is enabled on the linux host, as long as XShell can connect to the linux host through port 22, the connection can be successful

If there are multiple IPs, be sure to select which one you want to connect to, if there is only one, just default  

Write and debug the running program

Right click on the project, add a new item - add C++ source file

Next we write a normal program and generate it:

PS: The cross-platform running project can only use the debugging mode, so a breakpoint must be set in the program. Next, we set the breakpoint and start debugging the program. The right side is the Linux console window, which is the program output:

At this point, the entire Linux + Visual Studio2019 environment configuration (Ubantu16.04) related operations have been completed!

reference:

Vs2019 installation and usage tutorial (detailed) - a struggling little bird - blog garden

The above is the whole content of this article! If it is helpful to you, please like it! Favorite it! Welcome to leave a message in the comment area ! ! !

  

Guess you like

Origin blog.csdn.net/m0_61745661/article/details/125527727#comments_27756016