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

OpenCV调用cvNamedWindow报错未实现,新项目运行异常求解决

运行OpenCV时cvNamedWindow未实现错误解决

错误信息

terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.9.0-dev) /home/princess-ellie/opencv/modules/highgui/src/window.cpp:1255: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'.

相关文件内容

CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(img_processing VERSION 0.1.0 LANGUAGES C CXX)

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable(img_processing main.cpp)

target_link_libraries( img_processing ${OpenCV_LIBS} )

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

main.cpp

#include <iostream>
#include <opencv2/opencv.hpp>

int main(int, char **) {
    cv::Mat image;
    image = cv::imread("lena.jpg", cv::IMREAD_COLOR);
    cv::namedWindow("Lena", cv::WINDOW_AUTOSIZE);
    cv::imshow("Lena", image);
    return 0;
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/home/princess-ellie/opencv/include",
                "/usr/local/include/opencv4",
                "/usr/local/lib",
                "/usr/local/bin"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c23",
            "intelliSenseMode": "linux-gcc-x64",
            "cppStandard": "c++23"
        }
    ],
    "version": 4
}

问题背景

此前修改文件夹和项目名称前,项目可正常运行。删除原项目后新建项目,仍出现该错误,怀疑是VSCode配置问题,寻求解决方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 03:42:47