与CMAKE一起使用OpENCV时,对CV函数的未定义不确定

发布于 2025-01-29 22:53:03 字数 3200 浏览 2 评论 0原文

我正在关注一个教程( https://www.youtube.com/watch?v = m9hbm1m_emu < /a>)用于通过cmake使用OpenCV,当我尝试使用mingw-w64构建时,我会出现以下错误。

[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/bnick/Desktop/opencvtest/build --config Debug --target all -j 8 --
[build] Consolidate compiler generated dependencies of target opencvtest
[build] [ 50%] Linking CXX executable opencvtest.exe
[build] CMakeFiles\opencvtest.dir/objects.a(main.cpp.obj): In function `main':
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:8: undefined reference to `cv::Mat::Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::Mat::operator=(cv::Mat&&)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::Mat::~Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:15: undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:16: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:17: undefined reference to `cv::waitKey(int)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:8: undefined reference to `cv::Mat::~Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::Mat::~Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:8: undefined reference to `cv::Mat::~Mat()'
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make.exe[2]: *** [CMakeFiles\opencvtest.dir\build.make:115: opencvtest.exe] Error 1
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:838: CMakeFiles/opencvtest.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:120: all] Error 2
[build] Build finished with exit code 2

这是我的cmakelists.txt

cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)

include(CTest)
enable_testing()

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

add_executable(opencvtest main.cpp)

target_link_libraries( opencvtest ${OpenCV_LIBS} )

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

,这是我的主要cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
int main(int argc, char** argv )
{

    Mat image;
    image = imread("C:/Users/kemik/OneDrive/Skrivebord/Images/lenna.png");
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);
    waitKey(0);
    return 0;
}

I am following a tutorial (https://www.youtube.com/watch?v=m9HBM1m_EMU) for using OpenCV through CMake and I am having the following errors when I try to build using mingw-w64.

[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/bnick/Desktop/opencvtest/build --config Debug --target all -j 8 --
[build] Consolidate compiler generated dependencies of target opencvtest
[build] [ 50%] Linking CXX executable opencvtest.exe
[build] CMakeFiles\opencvtest.dir/objects.a(main.cpp.obj): In function `main':
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:8: undefined reference to `cv::Mat::Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::Mat::operator=(cv::Mat&&)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::Mat::~Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:15: undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:16: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:17: undefined reference to `cv::waitKey(int)'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:8: undefined reference to `cv::Mat::~Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:9: undefined reference to `cv::Mat::~Mat()'
[build] C:/Users/bnick/Desktop/opencvtest/main.cpp:8: undefined reference to `cv::Mat::~Mat()'
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make.exe[2]: *** [CMakeFiles\opencvtest.dir\build.make:115: opencvtest.exe] Error 1
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:838: CMakeFiles/opencvtest.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:120: all] Error 2
[build] Build finished with exit code 2

Here is the my CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)

include(CTest)
enable_testing()

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

add_executable(opencvtest main.cpp)

target_link_libraries( opencvtest ${OpenCV_LIBS} )

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

And this is my main.cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
int main(int argc, char** argv )
{

    Mat image;
    image = imread("C:/Users/kemik/OneDrive/Skrivebord/Images/lenna.png");
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);
    waitKey(0);
    return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文