所以我从这里下载了OpenCV库 https://sourceforge.net/projects/opencvlibrary/files/3.4.6/opencv-3.4.6-vc14_vc15.exe/download
带有cmakelist.txt的CMake gui
cmake_minimum_required(版本2.8)
项目(显示)
find_package(需要OpenCV)
消息(状态“ OpenCV库 status:“)message(STATUS” config: $ {OpenCV_DIR}“)消息(状态”
版本:$ {OpenCV_VERSION}“) message(STATUS“库: $ {OpenCV_LIBS}“)消息(状态”
包含路径:$ {OpenCV_INCLUDE_DIRS}“)add_executable(显示 DisplayImage.cpp)
target_link_libraries(显示 $ {OpenCV_LIBS})
并拥有一个像这样的简单cpp
#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv )
{
// cout << "You have entered " << argc
// << " arguments:" << "\n";
// for (int i = 0; i < argc; ++i)
// cout << argv[i] << "\n";
// cout << "a" << argv[1];
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
printf("Hello World!");
return 0;
}
已经使用cmake-gui对其进行了配置,并且显示出来了
OpenCV库状态: 配置:D:/ opencv / build / x64 / vc15 / lib 版本:3.4.6 库:opencv_calib3d; opencv_core; opencv_dnn; opencv_features2d; opencv_flann; opencv_highgui; opencv_imgcodecs; opencv_imgproc; opencv_ml; opencv_objdetect; opencv_photo; opencv_shape; opencv_v_sv_video; opencv_video_open; vc_open_v; 包含路径:D:/ opencv / build / include; D:/ opencv / build / include / opencv; D:/ opencv / build / include / opencv2 配置完成生成完成
似乎不错吧?然后在命令提示符下的生成目录中,我输入mingw32-make
这出现了
CMakeFiles \ Display.dir / objects.a(DisplayImage.cpp.obj):DisplayImage.cpp :(。text + 0x72): 未定义的引用
cv::imread(cv::String const&, int)' CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text+0xe3): undefined reference to
cv :: namedWindow(cv :: String const&, int)' CMakeFiles \ Display.dir / objects.a(DisplayImage.cpp.obj):DisplayImage.cpp :(。text + 0x129): 未定义的引用cv::imshow(cv::String const&, cv::_InputArray const&)' CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text+0x149): undefined reference to
cv :: waitKey(int)' CMakeFiles \ Display.dir / objects.a(DisplayImage.cpp.obj):DisplayImage.cpp :(。text $ _ZN2cv6StringC1EPKc [__ ZN2cv6StringC1EPKc] + 0x42): 未定义的引用cv::String::allocate(unsigned int)' CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf): undefined reference to
cv :: String :: deallocate()' CMakeFiles \ Display.dir / objects.a(DisplayImage.cpp.obj):DisplayImage.cpp :(。text $ ZN2cv6StringaSERKS0 [__ ZN2cv6StringaSERKS0 _] + 0x1c): 未定义的引用cv::String::deallocate()' CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to
cv :: fastFree(void *)' CMakeFiles \ Display.dir / objects.a(DisplayImage.cpp.obj):DisplayImage.cpp :(。text $ _ZN2cv3Mat7releaseEv [__ ZN2cv3Mat7releaseEv] + 0x40): 未定义的引用cv::Mat::deallocate()' CMakeFiles\Display.dir/objects.a(DisplayImage.cpp.obj):DisplayImage.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4): undefined reference to
cv :: fastFree(void *)'collect2.exe: 错误:ld返回1退出状态 mingw32-make [2]: * [CMakeFiles \ Display.dir \ build.make:104: Display.exe]错误1 mingw32-make [1]: * [CMakeFiles \ Makefile2:72:CMakeFiles / Display.dir / all]错误2 mingw32-make:*** [Makefile:83:全部] 错误2
我该如何解决?还是因为我直接从网站上使用图书馆?
我还尝试了类似在imread
函数上输入错误参数的操作,然后键入mingw32-make
,它的确告诉我我使用了错误的参数。如果他们知道我使用了错误的参数,那么为什么他们不知道imread
的含义(或为什么它是未定义的引用?)?我正在使用Windows。
我对这些库,mingw和cmake还是很陌生,所以对我的问题很愚蠢感到抱歉。
这个问题不是重复的,因为,我使用Windows和mingw32-make,问这个问题的每个人都没有使用它,而且这个问题与我的情况不同。