配置vscode的gcc编译环境

尽量将下载好的mingw64设置在根目录

Ctrl-Shift-P打开c/c++编辑配置

进入后选择路径

然后设置IntelliSense模式

 当报错找不到任务时,需要将tasks.json和launch.json的name、preLaunchTask键设置为一致

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: g++.exe 生成活动文件",//需要与tasks.json相一致
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",//设置路径
            "setupCommands": [
              {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
              }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
          }
        
    ]
}

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:/mingw64/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

tasks.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",//与launch.json的部分相一致
            "command": "C:\\mingw64\\bin\\g++.exe",//设置路径
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装OpenCV库:在Linux系统中,可以使用包管理器安装OpenCV库,例如在Ubuntu系统中,可以使用以下命令安装: sudo apt-get install libopencv-dev 2. 安装VSCode:在官网上下载VSCode的Linux版本,然后解压缩到指定目录即可。 3. 安装C++插件:在VSCode中安装C++插件,可以通过Extensions菜单进行安装。 4. 配置编译器:在VSCode中打开一个C++文件,然后按下Ctrl+Shift+B,选择“配置任务”,然后选择“C++编译器”,然后在弹出的窗口中输入以下内容: { "version": "2..", "tasks": [ { "label": "build", "type": "shell", "command": "g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "group": { "kind": "build", "isDefault": true } } ] } 5. 配置OpenCV库:在VSCode中打开一个C++文件,然后按下Ctrl+Shift+P,选择“C++: Edit Configurations”,然后在弹出的窗口中输入以下内容: { "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "/usr/include/opencv4" ], "defines": [], "compilerPath": "/usr/bin/g++", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 } 6. 编写代码:在VSCode中打开一个C++文件,然后编写OpenCV代码,例如: #include <opencv2/opencv.hpp> using namespace cv; int main() { Mat img = imread("test.jpg"); imshow("Image", img); waitKey(); return ; } 7. 编译运行:在VSCode中按下Ctrl+Shift+B,选择“build”,然后在终端中输入以下命令运行程序: ./test 以上就是在Linux下使用VSCode配置OpenCV的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值