记录VSCode 配置C++环境

按照我的步骤应该一定能够成功:


1.安装VSCode:Visual Studio Code - Code Editing. Redefined

2.安装MinGW:

2.1 Compare, Download & Develop Open Source & Business Software - SourceForge,搜索MinGW-w64,如下图所示

2.2 解压到某个位置(mingw64为解压出来的)

3.编译OpenCV

可以尝试一下,编译不成功就放弃。。。我放弃了,直接使用别人编译好的,爽歪歪!

GitHub - huihut/OpenCV-MinGW-Build: 👀 MinGW 32bit and 64bit version of OpenCV compiled on Windows. Including OpenCV 3.3.1, 3.4.1, 3.4.1-x64, 3.4.5, 3.4.6, 3.4.7, 3.4.8-x64, 3.4.9, 4.0.0-alpha-x64, 4.0.0-rc-x64, 4.0.1-x64, 4.1.0, 4.1.0-x64, 4.1.1-x64, 4.5.0-with-contrib, 4.5.2-x64下载对应的版本,放至某个路径。

4.配置VSCode

4.1 快速生成 launch.json, tasks.json, c_cpp_properties.json。

Run --> Add Configuration  生成 launch.json

Terminal --> Configure Default Build Task 生成tasks.json

Ctrl + Shift + P --> C/C++: Edit Configurations 生成c_cpp_properties.json

以下是我的配置,可以参考:

launch.json:

{  
    "version": "0.2.0",  
    "configurations": [  
        {  
            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示  
            "type": "cppdbg",       // 配置类型,这里只能为cppdbg  
            "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${workspaceFolder}/myutils/myutils.exe",// 将要进行调试的程序的路径  
            "args": [],             // 程序调试时传递给程序的命令行参数,一般设为空即可  
            "stopAtEntry": false,   // 设为true时程序将暂停在程序入口处,一般设置为false  
            "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  
            "environment": [],  
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台  
            "MIMode": "gdb",  
            "miDebuggerPath": "D:\\installed\\MinGW64\\seh\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应  
            "preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc  
            "setupCommands": [  
                {   
		    "description": "Enable pretty-printing for gdb",  
                    "text": "-enable-pretty-printing",  
                    "ignoreFailures": true  
                }  
            ]  
        }  
    ]  
}

tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
              "type": "shell",
              "label": "g++",
              "command": "D:\\installed\\MinGW64\\seh\\mingw64\\bin\\g++.exe",
              "args": [
                  "-g",
                  "-std=c++11",
                  "${file}",
                  "-o",
                  "${fileDirname}\\${fileBasenameNoExtension}.exe",
                  /*注意:此处导入的路径为编译后的opencv路径,请勿导入原始的opencv路径*/
                  "-I", "D:/installed/opencv341_MinGW/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/include/",
                  "-L", "D:/installed/opencv341_MinGW/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/x64/mingw/bin/",
                  "-l", "libopencv_calib3d341",
                  "-l", "libopencv_core341",
                  "-l", "libopencv_dnn341",
                  "-l", "libopencv_features2d341",
                  "-l", "libopencv_flann341",
                  "-l", "libopencv_highgui341",
                  "-l", "libopencv_imgcodecs341",
                  "-l", "libopencv_imgproc341",
                  "-l", "libopencv_ml341",
                  "-l", "libopencv_objdetect341",
                  "-l", "libopencv_photo341",
                  "-l", "libopencv_shape341",
                  "-l", "libopencv_stitching341",
                  "-l", "libopencv_superres341",
                  "-l", "libopencv_video341",
                  "-l", "libopencv_videoio341",
                  "-l", "libopencv_videostab341",
                  "-l", "opencv_ffmpeg341_64"
              ],// 编译命令参数
              "options": {
                   /*修改*/
                  "cwd": "D:\\installed\\MinGW64\\seh\\mingw64\\bin"
              },
              "problemMatcher": [
                  "$gcc"
              ],
              "group": {
                  "kind": "build",
                  "isDefault": true
              },
              "presentation": {
                  "panel": "new", //这里shared表示共享,改成new之后每个进程创建新的端口
              }
        }
    ]
}

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "D:/installed/MinGW64/seh/mingw64/include/*",
                "D:/installed/MinGW64/seh/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/*",
                "D:/installed/opencv341_MinGW/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/include/*",
                "D:/installed/opencv341_MinGW/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/include/opencv/*",
                "D:/installed/opencv341_MinGW/OpenCV-MinGW-Build-OpenCV-3.4.1-x64/include/opencv2/*"

            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-gcc-x64",
            "compilerPath": "D:\\installed\\MinGW64\\seh\\mingw64\\bin\\gcc.exe"
            
        }
    ],
    "version": 4
}

以上参考自:Opencv C++ MinGW VSCode fatal error to compile - Stack Overflow

=========================================================================

=========================================================================

=========================================================================

=========================================================================

以下是一些为了配置环境参考的一些博客,照着这些在用MinGW编译OpenCV时一直不成功,不知道跟我的电脑有没有关系,我用的公司的电脑,很垃圾的一台电脑。。。另外很多人的配置也是搞得眼花缭乱。。。

参考的一些博客:整理:Visual Studio Code (vscode) 配置C、C++环境/编写运行C、C++(主要Windows、简要Linux)_vscode配置c/c++环境-CSDN博客

1.MinGW:参考 MinGW C++ Download and Installation Instructions

2.CMake: VScode配置opencv_opencv vscode配置_cjjjstttt的博客-CSDN博客,下载页面 --> Index of /files/v3.20

3.launch.json, tasks.json, c_cpp_properties.json,参考 -->整理:Visual Studio Code (vscode) 配置C、C++环境/编写运行C、C++(主要Windows、简要Linux)_vscode配置c/c++环境-CSDN博客

             

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值