【问题标题】:Getting error while running opencv code in C在 C 中运行 opencv 代码时出错
【发布时间】:2018-11-25 03:19:28
【问题描述】:

我在 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文件夹中,这包含在路径变量中。

【问题讨论】:

  • @zindarod 成功了。

标签: c opencv


【解决方案1】:

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

你可以用g++编译你的代码:

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

【讨论】:

  • 问题不在于g++ 应该优先于gcc,问题在于pkg-config ... 出现在.c 文件之前。
  • @purplepsycho 是的,没错。但我想指出的是,C API 不再维护,所以即使 OP 正确使用了pkg-config,在使用gcc 编译代码时仍然会出现未定义的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-22
  • 2014-04-26
  • 2022-10-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多