https://code.visualstudio.com/Download
download code-stable-x64.tar.gz from https://code.visualstudio.com/docs/?dv=linux64
// 检测VSCode-linux-x64文件夹是否存在,否则解压code-stable-x64.tar.gz
// vi install_vscode.sh
#!/bin/bash
# 检查VSCode-linux-x64文件夹是否存在
vscode_folder="VSCode-linux-x64"
if [ -d "$vscode_folder" ]; then
echo "VSCode-linux-x64 folder already exists."
else
# 如果文件夹不存在,则解压code-stable-x64.tar.gz
tar -xzvf code-stable-x64*.tar.gz
# 或者使用以下命令解压(根据实际情况选择)
# tar -xzvf code-stable-x64.tar.gz -C /your/installation/path
echo "VSCode-linux-x64 folder extracted successfully."
fi
sudo apt-get update
sudo apt-get install -y build-essential # build-essential 是一个包,它包含了构建软件所需的基本工具,包括 gcc-9,libstdc++-9-dev,g++-9,make (4.2.1-1.2)。
kubuntu@kubuntu:/media/kubuntu/系统$ gdb -v
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
kubuntu@kubuntu:/media/kubuntu/系统$ cmake -version
Command 'cmake' not found, but can be installed with:
sudo apt install cmake
kubuntu@kubuntu:/media/kubuntu/系统$ g++ -v
Command 'g++' not found, but can be installed with:
sudo apt install g++
kubuntu@kubuntu:/media/kubuntu/系统$ gcc -v
Command 'gcc' not found, but can be installed with:
sudo apt install gcc
// vi install_cmake.sh
#!/bin/bash
# 检测是否存在CMake命令,使用 command -v 命令来检查是否存在 cmake 命令。如果存在,command -v 会返回 0,否则返回非零值。
if command -v cmake &> /dev/null; then
echo "CMake is already installed. Version: $(cmake --version | head -n1)"
else
echo "CMake is not installed on this system."
./cmake-3.26.3-linux-x86_64.sh --skip-licence --prefix=/usr
# 将CMake添加到PATH环境变量
# 暂时添加:export PATH="/usr/cmake-3.26.3-linux-x86_64/bin:$PATH"
echo 'export PATH="/usr/cmake-3.26.3-linux-x86_64/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
fi
// vi final_install_vscode.sh
#!/bin/bash
# 检查VSCode-linux-x64文件夹是否存在
vscode_folder="VSCode-linux-x64"
if [ -d "$vscode_folder" ]; then
echo "VSCode-linux-x64 folder already exists."
else
# 如果文件夹不存在,则解压code-stable-x64.tar.gz
tar -xzvf code-stable-x64*.tar.gz
# 或者使用以下命令解压(根据实际情况选择)
# tar -xzvf code-stable-x64.tar.gz -C /your/installation/path
echo "VSCode-linux-x64 folder extracted successfully."
fi
sudo apt-get update
sudo apt-get install -y build-essential
# 检测是否存在CMake命令,使用 command -v 命令来检查是否存在 cmake 命令。如果存在,command -v 会返回 0,否则返回非零值。
if command -v cmake &> /dev/null; then
echo "CMake is already installed. Version: $(cmake --version | head -n1)"
else
echo "CMake is not installed on this system."
# 暂时添加:export PATH="/usr/cmake-3.26.3-linux-x86_64/bin:$PATH"
./cmake-3.26.3-linux-x86_64.sh --skip-licence --prefix=/usr
echo " go ro run final_add_path.sh "
fi
// vi final_add_path.sh
#!/bin/bash
echo $PATH
echo 'export PATH="/usr/cmake-3.26.3-linux-x86_64/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
echo $PATH
// settings,json
{
"files.associations": {
"iostream": "cpp"
},
"cmake.cmakePath": "/usr/cmake-3.26.3-linux-x86_64/bin/cmake"
}
cmake_minimum_required(VERSION 3.0.0)
project(TEST VERSION 0.1.0 LANGUAGES C CXX)
include(CTest)
enable_testing()
add_executable(TEST main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
cmake_minimum_required(VERSION 3.0)
project(my_project)
# 添加可执行文件
add_executable(my_project main.cpp)
{
"version": "0.2.0",
"configurations": [
{
"name": "使用 CMake 调试",
"type": "cmake",
"request": "launch",
"program": "${workspaceFolder}/build/your_executable", // 替换为你的可执行文件的路径
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "cmake",
"setupCommands": [
{
"description": "启用 GDB 的漂亮打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"cmake": {
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"buildDirectory": "${workspaceFolder}/build"
},
"cmakeDebugType": "script",
"scriptPath": "${workspaceFolder}/.vscode/cmake-debugger.py" // 替换为你的 CMake 调试脚本的路径
}
]
}