在C中运行opencv代码时出错

时间:2018-06-15 09:37:29

标签: c opencv

我在C中有一个opencv代码:

#ifdef _CH_
#pragma package <opencv>
#endif

  #ifndef _EiC
    // motion templates sample code
 #include "cv.h"
   #include "highgui.h"
 #include <time.h>
 #include <math.h>
 #include <ctype.h>
#include <stdio.h>
#endif

使用这些头文件。

如果我使用

运行它
gcc `pkg-config --cflags --libs opencv` motempl_temp.c -o opencv

我收到错误:

/tmp/cc2rKXbX.o: In function `cvDecRefData':
motempl_temp.c:(.text+0xac2): undefined reference to `cvFree_'
motempl_temp.c:(.text+0xb4b): undefined reference to `cvFree_'
/tmp/cc2rKXbX.o: In function `cvGetRow':
motempl_temp.c:(.text+0xc63): undefined reference to `cvGetRows'
/tmp/cc2rKXbX.o: In function `cvGetCol':
motempl_temp.c:(.text+0xc91): undefined reference to `cvGetCols'
/tmp/cc2rKXbX.o: In function `cvReleaseMatND':
motempl_temp.c:(.text+0xcab): undefined reference to `cvReleaseMat'
/tmp/cc2rKXbX.o: In function `cvSubS':
motempl_temp.c:(.text+0xe08): undefined reference to `cvAddS'
/tmp/cc2rKXbX.o: In function `cvCloneSeq':
motempl_temp.c:(.text+0xe5a): undefined reference to `cvSeqSlice'
/tmp/cc2rKXbX.o: In function `cvSetNew':
motempl_temp.c:(.text+0xed6): undefined reference to `cvSetAdd'
/tmp/cc2rKXbX.o: In function `cvGetSetElem':
 motempl_temp.c:(.text+0xf93): undefined reference to `cvGetSeqElem'
/tmp/cc2rKXbX.o: In function `cvEllipseBox':
motempl_temp.c:(.text+0x1062): undefined reference to `cvEllipse'
/tmp/cc2rKXbX.o: In function `cvFont':
 motempl_temp.c:(.text+0x10ce): undefined reference to `cvInitFont'
    /tmp/cc2rKXbX.o: In function `cvReadIntByName':
 motempl_temp.c:(.text+0x11d8): undefined reference to 
  `cvGetFileNodeByName'
 /tmp/cc2rKXbX.o: In function `cvReadRealByName':
  motempl_temp.c:(.text+0x1277): undefined reference to 
  `cvGetFileNodeByName'
 /tmp/cc2rKXbX.o: In function `cvReadStringByName':
 motempl_temp.c:(.text+0x1306): undefined reference to 
 `cvGetFileNodeByName'
 /tmp/cc2rKXbX.o: In function `cvReadByName':
  motempl_temp.c:(.text+0x1349): undefined reference to 
 `cvGetFileNodeByName'

collect2: error: ld returned 1 exit status

所有头文件都在路径/usr/local/include/opencv文件夹中,这包含在路径变量中。

1 个答案:

答案 0 :(得分:2)

OpenCV C API is deprecated。您应该使用C ++ API。

您可以使用g++编译代码:

g++ motempl_temp.c -o opencv `pkg-config opencv --cflags --libs`