VsCode配置C、C++环境编写运行C、C++(Windows)

VsCode配置C、C++ opencv环境/编写运行C、C++(Windows)

这个方法不用安装MinGW

1.配置基本文件

首先在文件夹下新建.vscode文件,然后往里面放四个文件,具体的代码如下

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZCtqHCDW-1586364065084)(assets/1586363530833.png)]

.vscode\c_cpp_properties.json

第7,8行换成自己的opencv配置环境

第十六行换成自己的visual studio Hostx86/x64/cl.exe 路径

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:/Program Files/opencv/build/include",
                "D:/Program Files/opencv/build/include/opencv2"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "D:/Program Files/visual studio 2019/VC/Tools/MSVC/14.24.28314/bin/Hostx86/x64/cl.exe",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

.vscode\c_cpp_properties.json

这里的"program": "${fileDirname}\\main.exe"可以自己指定生成的exe的位置和名称

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "cl.exe debug",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileDirname}\\main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
        },

        {
            "name": "cl.exe build and debug active file",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileDirname}\\main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "preLaunchTask": "cl.exe build active file"
        }
    ]
}

.vscode\settings.json

配置一些需要的头文件

{
    "files.associations": {
        "fstream": "cpp",
        "iostream": "cpp",
        "vector": "cpp",
        "cmath": "cpp",
        "xstring": "cpp",
        "array": "cpp",
        "deque": "cpp",
        "initializer_list": "cpp",
        "list": "cpp",
        "queue": "cpp",
        "type_traits": "cpp",
        "xhash": "cpp",
        "xtree": "cpp"
    },
    "python.pythonPath": "D:\\Anaconda3\\python.exe"
}

.vscode\tasks.json

同样这里的17-21行要换成自己的opencv地址

{
// 有关 tasks.json 格式的文档,请参见
    // https://go.microsoft.com/fwlink/?LinkId=733558
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${fileDirname}\\main.exe",
                "twosum.cpp",
                "/I",
                "D:/Program Files/opencv/build/include",
                "/I",
                "D:/Program Files/opencv/build/include/opencv2",
                "/link",
                "D:/Program Files/opencv/build/x64/vc15/lib/opencv_world410.lib"
            ],
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "shell",
            "label": "cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build"
        }
    ]
}

2.编译

注意,在这个地方,首先要通过x86 x64 Cross Tools Command Prompt for VS 2019 这个打开,才能有vs环境,然后输入文件的地址,输入code,就自动打开vscode。

在这里插入图片描述

然后在左侧选第三个,run这里选第二个,点击三角形符号,就可以运行成功了。大功告成!

s Command Prompt for VS 2019 这个打开,才能有vs环境,然后输入文件的地址,输入code,就自动打开vscode。

[外链图片转存中…(img-Vp9K4QjR-1586364065086)]

然后在左侧选第三个,run这里选第二个,点击三角形符号,就可以运行成功了。大功告成!

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值