You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Qt+OpenCV项目编译报错:LNK2019未解析外部符号及mainwindow.obj缺失

Troubleshooting Your Hello_Qt_OpenCV Build Issues

Let's work through your problems step by step—since your other Qt-OpenCV projects compile fine, the issue is almost certainly tied to this specific project's configuration or build artifacts. Here's how to fix each problem:

1. Fixing LNK2019 & LNK1120 (Unresolved Symbols)

These errors mean your linker can't locate the compiled OpenCV code for cv::medianBlur and cv::GaussianBlur. The most likely culprit is a missing or mismatched library configuration in this project's .pro file:

  • Check your .pro file for Release-specific OpenCV links: OpenCV 3.2 uses distinct library names for Debug (ends with d) and Release builds. Make sure your .pro file explicitly handles both modes, like this:
    win32 {
        # Update this path to your OpenCV 3.2 build directory
        OPENCV_ROOT = C:/opencv-3.2.0/build
        INCLUDEPATH += $$OPENCV_ROOT/include
        LIBS += -L$$OPENCV_ROOT/x64/vc14/lib  # Match your Qt's compiler (vc14 = MSVC 2015, which Qt 5.7 uses)
        
        # Link correct libraries for Debug/Release
        CONFIG(debug, debug|release) {
            LIBS += opencv_world320d.lib
        } else {
            LIBS += opencv_world320.lib
        }
    }
    
    • If you're linking individual modules instead of opencv_world, ensure you add opencv_imgproc320.lib (Release) or opencv_imgproc320d.lib (Debug)—medianBlur and GaussianBlur live in the imgproc module.
  • Verify architecture match: Ensure you're building for x64 (if your OpenCV is compiled for x64) or x86, and that your Qt Creator kit matches this architecture. Mismatched 32/64-bit builds will trigger unresolved symbols.

2. Fixing "Cannot Find mainwindow.obj"

This typically points to corrupted build artifacts or a misconfigured project file:

  • Delete the entire build directory manually: Qt Creator's "Clean" sometimes leaves leftover files. Navigate to your project folder, delete the build-Hello_Qt_OpenCV-* folder (tied to your kit name), then restart Qt Creator.
  • Confirm mainwindow.cpp is included in the project: In Qt Creator's project pane, check that mainwindow.cpp has a checkmark next to it—if it's unchecked, it won't be compiled, so no .obj file is generated.
  • Re-run qmake properly: After deleting the build folder, open your project, go to Build > Run qmake, then do a full rebuild (Build > Rebuild All).

3. Quick Code Sanity Check

Just to rule out code-level oversights:

  • Ensure mainwindow.cpp includes the necessary OpenCV headers: Add #include <opencv2/opencv.hpp> or at minimum #include <opencv2/imgproc/imgproc.hpp> to access the blur functions.
  • Double-check that you're using the cv:: namespace correctly (your error log confirms this, but it's worth eliminating typos).

If you've tried all this and still have issues, sharing your .pro file and full build log will help narrow down remaining edge cases.

内容的提问来源于stack exchange,提问作者jwm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:40:14