c++ - 无法使用带有 msvc 的 OpenCV 调试构建来编译项目
问题描述
opencv_world451d.lib
helloworld.obj
helloworld.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow@cv@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV_InputArray@1@@Z) referenced in function main
C:\Users\kaito\OneDrive\Documents\Cpp\OpenCVHelloWorld\helloworld.exe : fatal error LNK1120: 1 unresolved externals
当我使用 OpenCV debug buildopencv_world451d.lib
时,vscode 不会编译我的项目。如果我切换到 OpenCV release build opencv_world451.lib
,那么一切都很好。
这很奇怪,因为我在 Visual Studio 2019 中使用了完全相同的设置,并且无论是调试还是发布版本都一切正常。CMake 也构建它。
这是我的tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Wall",
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"/I",
"C:/Program Files/opencv/build/include",
"/link",
"/LIBPATH:C:/Program Files/opencv/build/x64/vc15/lib",
"opencv_world451d.lib"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always"
},
"detail": "compiler: cl.exe"
}
]
}
使用调试构建时是否需要正确设置任何设置?
解决方案
我通过使用编译器标志 /MDd 而不是 /MD 解决了这个问题。看起来调试构建需要适当的调试运行时。
推荐阅读
- java - 一次对多个项目进行 Java Proguard 混淆(或保存接口包含定义)?
- tensorflow - BatchNormalization 层导致从 .h5 转换为 .onnx 时出错
- r - 为什么我的数据在“dr4pl”剂量反应曲线中生成“参数长度为零”?
- tsql - 我如何从 Sybase 脚本翻译来创建视图和索引结构
- patch - xpto.cli 脚本应用累积补丁、重启实例和获取版本
- java - 改造响应数组或对象
- nuxt.js - 使用 nuxt-composition-api 在路由更改上重新初始化 Vue3 可组合函数
- linkedin - LinkedIn 添加产品媒体不起作用公司 -> 产品
- sql-server - Microsoft Access 跨表查询 - 如何转换为 MSSQL 视图
- tesseract - Is there a way to get possible characters for a image (containing single character) in tesseract?