(Vscode)Linux遠程c/c++環境搭建
Linux端安裝基礎軟件
1、換源
vi /etc/apt/sources.list
//阿里雲源 18.04
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
//20.04
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
1、安裝ssh
sudo apt-get install openssh-server
2、安裝gcc,g++
sudo apt-get install gcc g++
3、安裝gdb
sudo apt-get install gdb
4、安裝cmake
sudo apt-get install cmake
5、安裝open_vm_tools
Vmware Tools工具官方已經不建議。更提倡開源的open-vm-tools,所以我安裝了這個:
sudo apt install open-vm-tools
#如果要實現文件夾共享,需要安裝 open-vm-tools-dkms
sudo apt install open-vm-tools-dkms
#桌面環境還需要安裝 open-vm-tools-desktop 以支持雙向拖放文件
sudo apt install open-vm-tools-desktop
Vscode安裝插件並配置免密登錄
1、安裝Remote -ssh插件
2、配置免密登錄
先在window下生成公鑰:
ssh-keygen -t rsa
再在linux下生成公鑰
ssh-keygen -t rsa
在linux生成公鑰的目錄下,創建authorized_keys文件,並寫入windows下生成的公鑰
Vscode在Linux下導入頭文件警告
這是因為在配置中沒有指定依賴路徑導致的,在c_cpp_properties.json文件中includePath的默認配置只有當前目錄,需要將系統依賴導入進去。
編輯~/.vscode/c_cpp_properties.json
(ctrl + shift + p,鍵入C/Cpp : Edit Configurations,這樣就打開了配置文件), 在includePath字段添加頭文件的路徑即可
在linux系統中輸入命令:
gcc -v -E -x c++ -
將最后面的include路徑都添加到c_cpp_properties.json文件中,該文件在vscode工作目錄下.vscode文件夾中