(VsCode): Linux remote c/c++ environment construction

table of Contents

Install basic software on Linux

Install ssh

Install g++

Install gdb

Install cmake

VsCode install service plugin

Establish remote connection configuration

Remote need to install the plug-in again

Create project example

Remote debugging example

Install basic software on Linux

Install ssh

yum install openssh-server #安装

service sshd status #查看状态

Install g++

# 安装g++ 要用root权限运行
yum install gcc-c++

g++ -v #查看版本

Install gdb

yum install gdb #安装

gdb -v  #查看版本

Install cmake

yum install cmake #安装

cmake --version #查看版本

make --version #查看版本

VsCode install service plugin

  • Remote  -Containers
  • Remote  -SSH
  • Remote  -SSH:Editing Configuration Files
  • Remote  -WSL
  • Remote  -Containers

Establish remote connection configuration

 

  • Select the platform (here, select linux), enter the password to connect to the storage server to connect .

Remote need to install the plug-in again

Create project example

  • Create folder, get path

  • Open folder

  • Create Cmake project (Ctrl + Shift + p)

  • Create case file

  • hello.txt
This is a test!
  • main.cpp
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int ,char**){
    int fd = open("../hello.txt", O_RDWR);
    if (-1 == fd){
        std::cerr << "erro \n" ;
        return -1;
    }
for(;;){
    char buffer[1024] = {};
    ssize_t len = read(fd, buffer, sizeof(buffer));
    if(0 == len){
        break;
    }  
    buffer[len] = '\0';
    std::cout << buffer << std::endl;
}
    close(fd);
    return 0;
}
  • Compilation output

Remote debugging example

  • Set via configuration file

  • Use absolute path when debugging, otherwise an error will be reported (after modification, compile first and then debug)

  • To debug

Guess you like

Origin blog.csdn.net/baidu_41388533/article/details/108907885