asp 做網(wǎng)站的缺點世界排名前十位
1.添加環(huán)境變量
D:\mingw64\bin
2.安裝vscode
3.下載opencv 4.8.0
4.程序引用第三方庫(opencv為例)
打開CMakeLists.txt,引入頭文件,使用include_directories 加入頭文件所在目錄。靜態(tài)鏈接庫link_directories
# 頭文件
include_directories(D:/opencv4.8.0/opencv/build/include)
# 靜態(tài)鏈接庫
link_directories(D:/opencv4.8.0/opencv/build/x64/vc16/lib)
在main 函數(shù)所在文件 添加 #pragma comment(lib,“xxx.lib”),如果當(dāng)前程序是Debug
加 opencv_world480d.lib;否則加opencv_world480.lib
#pragma comment(lib, "opencv_world480d.lib")
5.測試代碼
#include <opencv2/opencv.hpp>
#include <iostream>
#pragma comment(lib, "opencv_world480d.lib")
using namespace cv;
using namespace std;int main(int argc, char** argv) {Mat src = imread("D:/Work/opencv_test/images/1.jpeg");if (src.empty()) {cout << "could not load image..." << endl;return -1;}imshow("input", src);waitKey(0);return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.28.0)
project(cpp_test)set(CMAKE_GENERATOR "MinGW Makefiles")
# 頭文件
include_directories(D:/opencv4.8.0/opencv/build/include)
# 靜態(tài)鏈接庫
link_directories(D:/opencv4.8.0/opencv/build/x64/vc16/lib)
add_executable(app test01.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
tasks.json
{"version": "2.0.0","options": {"cwd": "${workspaceFolder}/build"},"tasks": [{"type": "shell","label": "cmake","command": "cmake","args": [".."]},{"label": "make","group": "build","command": "make","args": [],"problemMatcher": []},{"label": "Build","dependsOrder": "sequence","dependsOn": ["cmake","make"]},{"type": "cppbuild",//"label": "C/C++: g++ 生成活動文件","label": "Build",// "command": "/usr/bin/g++","command": "D://mingw64//bin//g++.exe","args": ["-fdiagnostics-color=always","-g","-o","${workspaceFolder}/bin/Debug/app.exe","-fexec-charset=GBK"],"options": {"cwd": "${workspaceFolder}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "D://mingw64//bin//g++.exe"}]
}
launch.json
{// 使用 IntelliSense 了解相關(guān)屬性。 // 懸停以查看現(xiàn)有屬性的描述。// 欲了解更多信息,請訪問: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "(gdb) 啟動","type": "cppdbg","request": "launch","program": "${workspaceFolder}/bin/Debug/app.exe","args": ["-I", "D:\\opencv4.8.0\\opencv\\build\\include",//改成你自己的"-I", "D:\\opencv4.8.0\\opencv\\build\\include\\opencv2",//改成你自己的],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "為 gdb 啟用整齊打印","text": "-enable-pretty-printing","ignoreFailures": true},],"preLaunchTask": "Build","miDebuggerPath": "D://mingw64//bin//gdb.exe", // 修改為你的 gdb 路徑},]
}
參考文章:
VScode編寫C++概述(VScode 使用opencv與Eigen為例)_vscode c++使用opencv msvc-CSDN博客https://blog.csdn.net/euphorias/article/details/120783669
windows環(huán)境下cmake創(chuàng)建MinGW類型makefile報錯_cmake error: error: generator : mingw makefiles-CSDN博客https://blog.csdn.net/weixin_48876595/article/details/129414407