与CMAKE一起使用OpENCV时,对CV函数的未定义不确定
我正在关注一个教程( 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论