vscode使用Cmake环境搭建

1、下载编译器MinGW,https://osdn.net/projects/mingw/。下载完成安装;
在这里插入图片描述
2、下载Cmake编译,https://cmake.org/download/ ,下载完成安装;
3、Vscode EXTENSIONS下载CMake和CMake Tools,C/C++;
在这里插入图片描述
4、测试程序,新建文件夹,新建文件写一个测试程序
在这里插入图片描述5、CMakeLists编写;
在这里插入图片描述
cmake_minimum_required(VERSION 3.0.0)
project(test)
SET(CMAKE_BUILD_TYPE “Debug”) #设置debug版本编译
include_directories(./)
aux_source_directory(./ DIR_SRC)
#aux_source_directory(./ DIR_DEMO)
#add_subdirectory(./src)

add_executable(main ${DIR_SRC} )

6、编译器配置:Ctrl+Shift+p:输入C/Cpp:Edit Configurations生成配置文件 c_cpp_properties.json
在这里插入图片描述

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:/programfile/mingw/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64",
            "configurationProvider": "vector-of-bool.cmake-tools"
        }
    ],
    "version": 4
}

7、仿真配置:Ctrl+Shift+p:输入Open launch.json生成配置文件launch.json
在这里插入图片描述

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/test/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/programfile/mingw/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

8、Ctrl+Shift+p:输入Tasks: Configure task生成配置文件 tasks.json
在这里插入图片描述

{
    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"], // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

9、Ctrl+Shift+p:打开配置文件 settings.json
在这里插入图片描述添加:“cmake.cmakePath”: “D:/programfile/cmake-3.20.2/bin/cmake.exe”
10、编译如果出现make时错误,“make : 无法将“make”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。”
解决方法:将安装的minGW/bin文件下,找到mingw32-make.exe文件,重命名为make.exe即可。

11、Vscode下打开终端,进入工程,先使用Cmake编译生成Makefile,在make编译生成可执行文件。

12、仿真调试,或者在终端上直接运行

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值