2
  • libcv开发安装
  • 10.04

关于以下定义的任何想法?

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
4

3 回答 3

5

我试过这个,它对我有用:

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

我是从:https ://askubuntu.com/questions/239891/opencv-program-wont-compile-quantal

于 2014-04-16T20:26:11.220 回答
3

看来您没有链接到 OpenCV 库;根据本指南,编译 OpenCV 程序的一种方法(在正确配置 OpenCV 之后)是

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

如果您的 C++ 代码是在单独的步骤中编译的,您可能会删除该--cflags部分。

于 2012-08-23T19:14:07.177 回答
0

您需要包含使用 pkg-config 和 cflags 的库。

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

有关更多详细信息,请参阅此链接http://www.jayrambhia.com/blog/2012/05/08/beginning-opencv/

于 2012-08-23T21:33:06.557 回答