簡體   English   中英

無法使用 OpenCV 調試版本和 msvc 編譯項目

[英]Can't compile project using OpenCV debug build with msvc

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 build opencv_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 來解決問題。 看起來調試構建需要適當的調試運行時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM