use vscode mingw cmake on windows

news/2024/7/16 10:22:10 标签: vscode, windows, ide

记住mingw去官网下面的MingW-W64-builds, 下这个版本
x86_64-13.1.0-release-posix-seh-ucrt-rt_v11-rev1.7z
posix很重要, win32版本没线程支持,用到会报错

可以测试下是否能正常运行

#include <thread>
#include <mutex>
#include <condition_variable>
#include <iostream>

std::thread second_workthread;
std::mutex mtx;
std::condition_variable objectDetectorRun;

task.json
安好mingw, cmake

{
    "version": "2.0.0",
    "windows": {
        "options": {
            "shell": {
                "executable": "powershell"
            }
        }
    },
    "type": "shell",
    "options": {
        "cwd": "${workspaceRoot}"
    },
    "tasks": [
        {
            "label": "cmake",
            "linux": {
                "command": "cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug .."
            },
            "windows": {
                "command": "cmake -G 'MinGW Makefiles' .."
            },
            "type": "shell",
            "dependsOn": "_makebuildfolder",
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": [],
            "group": "build"
        },
        {
            "label": "make",
            "linux": {
                "command": "make -j 8"
            },
            "windows": {
                "command": "mingw32-make -j 4"
            },
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "panel": "shared"
            },
            "isBuildCommand": true,
            "problemMatcher": [],
            "group": "build"
        },
        {
            "label": "_makebuildfolder",
            "type": "shell",
            "linux": {
                "command": "mkdir -p ${workspaceFolder}/build"
            },
            "windows": {
                "command": "mkdir -Force ${workspaceFolder}/build"
            },
            "problemMatcher": [],
            "group": "build"
        },
        {
            "label": "copy_raw",
            "type": "shell",
            "linux": {
                "command": "mkdir -p ${workspaceFolder}/build"
            },
            "windows": {
                "command": "Copy ${workspaceFolder}/*.raw ${workspaceFolder}/build "
            }
        },
        {
            "label": "run",
            "args": ["32"],
            "windows": {
                "command": "${command:cmake.launchTargetPath}"
            },
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
        },
        {
            "label": "runwithbuild",
            "args": ["32"],
            "windows": {
                "command": "${command:cmake.launchTargetPath}"
            },
            "dependsOrder": "sequence", //tj : make sure exe deps in order
            "dependsOn": ["cmake", "make", "copy_raw"],
            "options": {
                "cwd": "${workspaceRoot}/build"
            },
        }
    ]
}

对于opencv, 要么自己用Mingw编译, 要么下载现存的, 我这里下的现成的https://github.com/huihut/OpenCV-MinGW-Build

cmake_minimum_required( VERSION 3.5 )
project( main )

set(CMAKE_CXX_FLAGS "-std=c++14")
set (OpenCV_DIR C:\\Software\\OpenCV-MinGW-Build)
find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})


add_executable( main main.cpp )
target_link_libraries( main ${Pangolin_LIBRARIES} )

debug的话

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",
            "targetArchitecture": "x86",
            "program": "${command:cmake.launchTargetPath}",
            // "program": "${workspaceFolder}/build/main.exe",
            // "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": ["32"],//左边启动debug, 从这里pick up args
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/build",
            "environment": [
                {
                    "name": "PATH",
                    "value": "${env:Path};C:\\Workspace\\v-nova\\build"
                    //这里设置错了,容易出现Unable to start debugging. Unexpected GDB output from command “-exec-run“
                }
            ],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Software/mingw64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        }
    ]
}

需要配置用 cmake:configure with cmake debugger

在这里插入图片描述

注意最下面的状态栏, 如果没有设置点进去设置
另外 cmake可能会让把

C:\Software\OpenCV-MinGW-Build\x64\mingw\bin

加入环境变量

如果传参在launch.json 不work的话, 在setting.json里面加上

从状态栏启动debug的话, 设置 args要在setting.json里面

{
    "cmake.configureOnOpen": false,
    "files.associations": {
        "ostream": "cpp",
        "mutex": "cpp",
        "array": "cpp",
        "string": "cpp",
        "string_view": "cpp"
    },
    "C_Cpp.default.compilerPath": "C:\\Software\\mingw64\\bin\\g++.exe",
    "cmake.debugConfig": {
        "args": [
            "32"//下面启动debug从这里Pick up args
        ]
    }
}

从左边启动debug的话, args在launch.json里面设置

https://github.com/microsoft/vscode-cmake-tools/issues/121


http://www.niftyadmin.cn/n/5017890.html

相关文章

基于keras中Lenet对于mnist的处理

文章目录 MNIST导入必要的包加载数据可视化数据集查看数据集的分布开始训练画出loss图画出accuracy图 使用数据外的图来测试图片可视化转化灰度图的可视化可视化卷积层的特征图第一层卷积 conv1 和 pool1第二层卷积 conv2 和 pool2 MNIST MNIST&#xff08;Modified National …

linux espidf vscode

安装 根据 https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32s2/get-started/linux-macos-setup.html 里的要求安装一些东西&#xff0c;点插件的首页的“… Package”也能跳转 在 vscode 里安装 ESP-IDF 插件&#xff0c;下载服务器选择 Espressif&#xff0c…

【leetcode 力扣刷题】删除字符串中的子串or字符以满足要求

删除字符串中的子串或者字符以满足题意要求 1234. 替换子串得到平衡字符串680. 验证回文串917. 仅仅反转字母 1234. 替换子串得到平衡字符串 题目链接&#xff1a;1234. 替换子串得到平衡字符串 题目内容&#xff1a; 题目中给出了平衡字符串的定义——只有’Q’&#xff0c;…

javascript实战开发:json数据求指定元素的和算法(2)

项目需求 使用javascript,在格式如下&#xff1a; [{"data":{propertyType: "电量,A相电流,电功率"},"odata": {"prev_0_day_val_diff": "10.189941,-3.0,79.0",} },{"data":{propertyType: "A相电流,电功…

nextTick实现原理 微任务

什么是nextTick? 定义: 在下次 DOM 更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法&#xff0c;获取更新后的 DOM 看完这个定义不免心生疑问&#xff1a; 下次 DOM 更新循环结束之后是什么时候?执行延迟回调?更新后的 DOM? 基于以上问题和平时的使用经验…

Linux--popen函数

#include <stdio.h>FILE *popen(const char *command, const char *mode); int pclose(FILE *stream); /* command&#xff1a; 是一个指向以 NULL 结束的 shell 命令字符串的指针。这行命令将被传到 bin/sh 并使用 -c 标志&#xff0c;shell 将执行这个命令。 mode&…

Android学习之路(14) Context详解

一. 简介 在 Android 开发中、亦或是面试中都离不开四大组件的身影&#xff0c;而在创建或启动这些组件时&#xff0c;并不能直接通过 new 关键字后跟类名来创建实例对象&#xff0c;而是需要有它们各自的上下文环境&#xff0c;也就是本篇文章要讨论的 Context。 1.1 Contex…

lv4 嵌入式开发-6 格式化输入输出

目录 1 标准I/O – 格式化输出 2 标准I/O – 格式化输入 3 小结 4 标准I/O – 思考和练习 1 标准I/O – 格式化输出 #include <stdio.h> int printf(const char *fmt, …); int fprintf(FILE *stream, const char *fmt, …); int sprintf(char *s, const char *f…