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

Ubuntu16.04编译OpenCV2.4.13时出现Q_WS_WIN未声明CMake错误

Fixing "Q_WS_WIN was not declared in this scope" Error When Building OpenCV 2.4.13 on Ubuntu 16.04

Hey there, let's work through this frustrating error you're facing. The Q_WS_WIN macro is a Qt-specific flag for Windows platforms—so it makes total sense it's throwing an error on Ubuntu. Older OpenCV versions like 2.4.13 have some quirks with Qt detection on non-Windows systems, but here are a few solid fixes to try:

1. Disable Qt Integration (Quickest Fix)

If you don't need OpenCV's Qt-based GUI features, the simplest solution is to tell CMake to skip Qt entirely. Delete your existing release build folder first to clear old cached configs, then run:

mkdir -p release && cd release
cmake -DWITH_QT=OFF -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)

This bypasses the problematic Qt-related checks entirely.

2. Fix Qt Detection (If You Need Qt Support)

If you do need OpenCV to work with Qt, Ubuntu 16.04 ships with Qt5 by default, and Q_WS_WIN was deprecated in Qt5. Here's how to configure CMake correctly:

  • First, install the required Qt5 dev packages:
    sudo apt-get update && sudo apt-get install qt5-default qttools5-dev-tools
    
  • Then, run CMake with explicit Qt5 settings (and still avoid the Windows macro check):
    rm -rf release && mkdir release && cd release
    cmake -DWITH_QT=ON -DQT_QMAKE_EXECUTABLE=/usr/bin/qmake -DCMAKE_BUILD_TYPE=Release ..
    make -j$(nproc)
    

This tells OpenCV to use the system's Qt5, which doesn't reference the outdated Q_WS_WIN macro.

3. Manually Patch OpenCV's CMake Config

If the above steps don't work, you can directly modify OpenCV's CMake scripts to skip checking for Q_WS_WIN on Linux:

  1. Navigate to your OpenCV source directory and open cmake/OpenCVFindQt.cmake in a text editor.
  2. Look for lines that look like this:
    check_symbol_exists(Q_WS_WIN "${QT_INCLUDE_DIR}/QtGui/qglobal.h" HAVE_Q_WS_WIN)
    
  3. Wrap that check in a Windows-only condition:
    if(WIN32)
      check_symbol_exists(Q_WS_WIN "${QT_INCLUDE_DIR}/QtGui/qglobal.h" HAVE_Q_WS_WIN)
    endif()
    
  4. Save the file, then re-run your CMake and build commands as usual.

This ensures the macro check only runs on Windows systems where it's relevant.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:54:58