主要是两个json设置
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"compilerPath": "D:/Libs/mingw810_64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:/Libs/mingw810_64/bin/g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}","${workspaceFolder}/src/*.cpp",
"-I",
"${workspaceFolder}/inc",
"-static-libgcc",
"-L",
"${workspaceFolder}/libs2",
"-l","libopencv_core440",
"-l","libopencv_highgui440",
"-l","libopencv_imgproc440",
"-l","libopencv_imgcodecs440",
"-o",
"${fileDirname}\\build_exe\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/Libs/mingw810_64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
遇到的问题有:
1.定义的h文件与cpp文件不能全部检测到,这一步需要通过task.json里面去进行添加,虽然有的介绍是从includePath中添加,但是,自己尝试并未成功,只能通过task.json添加才能成功。
2.添加dll或者lib文件,需要通过 -L 制定文件夹 -l 制定文件名称来确定。
整个过程类似于CMakeLists.txt ,按照这个过程理解就OK
参考:https://blog.csdn.net/qq_63032911/article/details/130500125