OpenCv未定义引用`cv :: [英] OpenCv undefined reference to `cv::
问题描述
#using namespace std;
#using namespace cv;
int main(int argc,const char ** argv)
{
Mat img = imread(MyPic.JPG,CV_LOAD_IMAGE_UNCHANGED);
if(img.empty())//检查图像是否加载
{
cout<<< 错误:图像无法加载.. !! << ENDL;
// system(pause); //等待按键
return -1;
}
namedWindow(MyWindow,CV_WINDOW_AUTOSIZE); //创建名为MyWindow的窗口
imshow(MyWindow,img); /
waitKey(0); //等待无限时间的按键
destroyWindow(MyWindow); //用名称破坏窗口,MyWindow
return 0;
}
16:11:28 ****增量构建项目的调试OpenCv ****
信息:内部构建器用于构建
g ++-IC:\\opencv\\build\\include-O0 -g3 -Wall -c -fmessage-length = 0 -osrc\\OpenCv.o ..\\src\\OpenCv.cpp
g ++-LC:\\opencv\\build\\x86\\vc12\\\\ LIB -o OpenCv.exe src\\OpenCv.o -lopencv_calib3d249 -lopencv_contrib249 -lopencv_core249 -lopencv_features2d249 -lopencv_flann249 -lopencv_gpu249 -lopencv_highgui249 -lopencv_imgproc249 -lopencv_legacy249 -lopencv_ml249 -lopencv_nonfree249 -lopencv_objdetect249 -lopencv_ocl249 -lopencv_photo249 -lopencv_stitching249 -lopencv_superres249 - lopencv_ts249 -lopencv_video249 -lopencv_videostab249
src\OpenCv.o:在函数`main'中:
C:\Users\ayberk101\workspace\OpenCv\Debug/../ src / OpenCv .cpp:10:未定义的引用`cv :: i mread(std :: string const& int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../ src / OpenCv.cpp:19:undefined reference to`cv :: namedWindow(std :: string const& int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../ src / OpenCv.cpp:20:未定义引用`cv :: _ InputArray :: _ InputArray(cv :: Mat const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../ src / OpenCv.cpp:20:未定义的引用`cv :: imshow(std :: string const& cv :: _ InputArray const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug /../ src /OpenCv.cpp:22:未定义的引用`cv :: waitKey(int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../ src / OpenCv.cpp: 24:undefined reference to`cv :: destroyWindow(std :: string const&)'
src\OpenCv.o:在函数`ZN2cv3MatD1Ev'中:
C:/ opencv / build / include / opencv2 /core/mat.hpp:278:未定义的引用`cv :: fas tFree(void *)'
src\OpenCv.o:在函数`ZN2cv3Mat7releaseEv'中:
C:/opencv/build/include/opencv2/core/mat.hpp:367:undefined reference to` cv :: Mat :: deallocate()'
collect2.exe:错误:ld返回1退出状态
问题1:您将不得不包含opencv / c ++头文件使其工作:
#includeopencv2 / core / core.hpp
#includeopencv2 / imgproc / imgproc.hpp
#includeopencv2 / highgui / highgui.hpp
#using namespace cv;
#include< iostream>
#using namespace std;
int main(){
...
那么,问题2:你不能用mingw使用vc12 libs。 (它是一个不同的编译器)
opencv没有更多的prebuild mingw库,所以在做任何其他的之前,你将不得不 build 使用cmake在本地使用opencv lib。
再次,你真的需要使用mingw / eclipse? (vs express仍然是免费的)
I am new at OpenCv. I am using Eclipse C/C++. When i try to run this sample code i faced with these errors. What should i do to solve this problem? Is there any problem at configurating ?
#using namespace std;
#using namespace cv;
int main( int argc, const char** argv )
{
Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED);
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); /
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
16:11:28 **** Incremental Build of configuration Debug for project OpenCv ****
Info: Internal Builder is used for build
g++ "-IC:\\opencv\\build\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\OpenCv.o" "..\\src\\OpenCv.cpp"
g++ "-LC:\\opencv\\build\\x86\\vc12\\lib" -o OpenCv.exe "src\\OpenCv.o" -lopencv_calib3d249 -lopencv_contrib249 -lopencv_core249 -lopencv_features2d249 -lopencv_flann249 -lopencv_gpu249 -lopencv_highgui249 -lopencv_imgproc249 -lopencv_legacy249 -lopencv_ml249 -lopencv_nonfree249 -lopencv_objdetect249 -lopencv_ocl249 -lopencv_photo249 -lopencv_stitching249 -lopencv_superres249 -lopencv_ts249 -lopencv_video249 -lopencv_videostab249
src\OpenCv.o: In function `main':
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:10: undefined reference to `cv::imread(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:19: undefined reference to `cv::namedWindow(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:22: undefined reference to `cv::waitKey(int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:24: undefined reference to `cv::destroyWindow(std::string const&)'
src\OpenCv.o: In function `ZN2cv3MatD1Ev':
C:/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
src\OpenCv.o: In function `ZN2cv3Mat7releaseEv':
C:/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
problem1: you will have to include opencv / c++ header files to make it work:
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#using namespace cv;
#include <iostream>
#using namespace std;
int main() {
...
then, problem2: you cannot use the vc12 libs with mingw. (it's a different compiler)
there are no more prebuild mingw libs for opencv, so, before doing anything else, you will have to build the opencv libs locally using cmake.
again, do you really need to use mingw / eclipse ? (vs express is still free)
这篇关于OpenCv未定义引用`cv ::的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!