简体   繁体   English

OpenCV 2.4.2:未定义的引用

[英]OpenCV 2.4.2: Undefined References

  • libcv-dev install libcv-dev安装
  • 10.04 10.04

Any ideas as to where the following might be defined? 关于可能定义以下内容的任何想法?

ahcarpenter@ahcarpenter-laptop:~$ g++ objectmarker.o -o objectmarker
objectmarker.o: In function `on_mouse(int, int, int, int, void*)':
objectmarker.cpp:(.text+0x12f): undefined reference to `cvCloneImage'
objectmarker.cpp:(.text+0x1d1): undefined reference to `cvRectangle'
objectmarker.cpp:(.text+0x1ea): undefined reference to `cvShowImage'
objectmarker.cpp:(.text+0x1f4): undefined reference to `cvReleaseImage'
objectmarker.o: In function `main':
objectmarker.cpp:(.text+0x391): undefined reference to `cvNamedWindow'
objectmarker.cpp:(.text+0x3aa): undefined reference to `cvSetMouseCallback'
objectmarker.cpp:(.text+0x4da): undefined reference to `cvLoadImage'
objectmarker.cpp:(.text+0x50f): undefined reference to `cvShowImage'
objectmarker.cpp:(.text+0x519): undefined reference to `cvWaitKey'
objectmarker.cpp:(.text+0x53f): undefined reference to `cvReleaseImage'
objectmarker.cpp:(.text+0x54e): undefined reference to `cvDestroyWindow'
objectmarker.cpp:(.text+0xd7f): undefined reference to `cvReleaseImage'
objectmarker.cpp:(.text+0xdf3): undefined reference to `cvDestroyWindow'
collect2: ld returned 1 exit status

I tried this and it worked for me: 我试过这个,它对我有用:

sudo g++ -I/usr/include/opencv main.cpp -o main -lopencv_core -lopencv_imgproc
 -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d
 -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -I /lib/
 -I /home/ubuntu/micros/opencv_directory/include/opencv

I got it from: https://askubuntu.com/questions/239891/opencv-program-wont-compile-quantal 我从它得到它: https//askubuntu.com/questions/239891/opencv-program-wont-compile-quantal

It seems you're not linking against the OpenCV libraries; 看来你没有链接OpenCV库; according to this guide , one way to compile an OpenCV program (after OpenCV has been properly configured) is 根据本指南 ,编译OpenCV程序的一种方法(在正确配置OpenCV之后)是

g++ `pkg-config opencv --cflags` my_code.cpp  -o my_code `pkg-config opencv --libs`

If your C++ code is compiled in a separate step, you can probably drop the --cflags part. 如果您的C ++代码是在单独的步骤中编译的,那么您可以删除--cflags部分。

You need to include libraries using pkg-config and cflags. 您需要使用pkg-config和cflags包含库。

$ g++ -ggdb `pkg-config --cflags opencv` -o `basename filename.cpp .cpp` filename.cpp `pkg-config --libs opencv

see this link for more details http://www.jayrambhia.com/blog/2012/05/08/beginning-opencv/ 有关详细信息,请参阅此链接http://www.jayrambhia.com/blog/2012/05/08/beginning-opencv/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM