当前位置: 首页 > news >正文

linux系统下vscode portable版本的c++/Cmake环境搭建001

linux系统下vscode portable版本的Cmake环境搭建

  • vscode portable 安装
  • 安装基本工具
    • 安装 build-essential
    • 安装 CMake
  • final script code
  • 安装插件
    • CMake Tools & cmake
    • C/C++ Extension Pack
  • Test
    • settings,json
    • CMakeLists.txt
    • 调试和运行工具
  • CG

  • 目的:希望在获得一个新的系统之后,以最简便的方式搭配一个能够运行与调试c++的编程环境

vscode portable 安装

  • 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" ]; thenecho "VSCode-linux-x64 folder already exists."
else# 如果文件夹不存在,则解压code-stable-x64.tar.gztar -xzvf code-stable-x64*.tar.gz# 或者使用以下命令解压(根据实际情况选择)# tar -xzvf code-stable-x64.tar.gz -C /your/installation/pathecho "VSCode-linux-x64 folder extracted successfully."
fi
  • bash ./install_vscode.sh
    在这里插入图片描述

安装基本工具

安装 build-essential

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)
  • 我的系统中默认安装了gdb
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 <http://gnu.org/licenses/gpl.html>
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

安装 CMake

  • 去https://github.com/Kitware/CMake/releases/下载需要版本的命令文件,比如wget https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.sh
// vi install_cmake.sh#!/bin/bash# 检测是否存在CMake命令,使用 command -v 命令来检查是否存在 cmake 命令。如果存在,command -v 会返回 0,否则返回非零值。
if command -v cmake &> /dev/null; thenecho "CMake is already installed. Version: $(cmake --version | head -n1)"
elseecho "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"' >> ~/.bashrcsource ~/.bashrc
fi

在这里插入图片描述

final script code

// vi final_install_vscode.sh#!/bin/bash
# 检查VSCode-linux-x64文件夹是否存在
vscode_folder="VSCode-linux-x64"if [ -d "$vscode_folder" ]; thenecho "VSCode-linux-x64 folder already exists."
else# 如果文件夹不存在,则解压code-stable-x64.tar.gztar -xzvf code-stable-x64*.tar.gz# 或者使用以下命令解压(根据实际情况选择)# tar -xzvf code-stable-x64.tar.gz -C /your/installation/pathecho "VSCode-linux-x64 folder extracted successfully."
fisudo apt-get update
sudo apt-get install -y build-essential# 检测是否存在CMake命令,使用 command -v 命令来检查是否存在 cmake 命令。如果存在,command -v 会返回 0,否则返回非零值。
if command -v cmake &> /dev/null; thenecho "CMake is already installed. Version: $(cmake --version | head -n1)"
elseecho "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=/usrecho " 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

安装插件

CMake Tools & cmake

在这里插入图片描述

在这里插入图片描述

C/C++ Extension Pack

在这里插入图片描述

Test

settings,json

  • 只需要简单配置settings,json即可
// settings,json
{"files.associations": {"iostream": "cpp"},"cmake.cmakePath": "/usr/cmake-3.26.3-linux-x86_64/bin/cmake"
}

CMakeLists.txt

  • 可以直接使用工具创建: F1->CMAKE QUICK START
    在这里插入图片描述
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)

调试和运行工具

  • 只需要左下角的几个按键即可
    在这里插入图片描述
  • 调试效果:在这里插入图片描述

CG

  • 如果按照以往的F5调试方案,会报错:The “cmake” debug type with “cmakeDebugType” set to “script” requires you to define a “scriptPath” that points to a CMake script. 需要将 launch.json 进行如下配置:
{"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 调试脚本的路径}]
}
http://www.lryc.cn/news/298288.html

相关文章:

  • 【QT+QGIS跨平台编译】之三十一:【FreeXL+Qt跨平台编译】(一套代码、一套框架,跨平台编译)
  • 2024年 前端JavaScript入门到精通 第一天
  • 155基于matlab 的形态学权重自适应图像去噪
  • 操作系统——内存管理(附带Leetcode算法题LRU)
  • I/O多路复用简记
  • SPECCPU2017操作说明
  • openresty (nginx)快速开始
  • 相机图像质量研究(11)常见问题总结:光学结构对成像的影响--像差
  • 【深度学习】基于多层感知机的手写数字识别
  • 给定n,m(200),构造一个n*m的矩阵a,使得每个4*4的子矩阵,左上角2*2的子矩阵的异或和等于右下角的,左下角的异或和等于右上角的
  • 【开源】基于JAVA+Vue+SpringBoot的假日旅社管理系统
  • kafka 文件存储机制
  • 引入BertTokenizer出现OSError: Can‘t load tokenizer for ‘bert-base-uncased‘.
  • 陶陶摘苹果C++
  • STM32F1 引脚重映射功能
  • c语言的各类输出函数(带完善更新)
  • 【linux温故】CFS调度
  • 计算机网络之一
  • 从一到无穷大 #23 《流计算系统图解》书评
  • 华为问界M9:领跑未来智能交通的自动驾驶黑科技
  • Java图形化界面编程——弹球游戏 笔记
  • 浅谈人工智能之深度学习~
  • 【复现】大华 DSS SQL 注入漏洞_46
  • Python 中的断点类型详解
  • 一步步建立一个C#项目(连续读取S7-1200PLC数据)
  • Hive窗口函数详解
  • 车载电子电器架构 —— 电子电气系统功能开发
  • LeetCode--代码详解 7.整数反转
  • 《统计学简易速速上手小册》第6章:多变量数据分析(2024 最新版)
  • 创新S3存储桶检索:Langchain社区S3加载器搭载OpenAI API