6

作为我正在进行的一个更大项目的一部分,我需要在 C 程序上使用 OpenCV 库。我在 Fedora 17 32 位中使用 yum 安装了 OpenCV 和 opencv-devel。我指示预处理器导入 opencv/cv.h 和 opencv/highgui.h 作为必要的头文件。

正如我所提到的,gcc 用于编译整个 C 项目。但是,链接器似乎存在问题。

每当我尝试编译项目 ( gcc opencv.c -o opencv) 时,我都会得到一个错误列表,类似于:

/tmp/ccLJWE0c.o: In function `cvRound': opencv.c:(.text+0x19):
undefined reference to `lrint' /tmp/ccLJWE0c.o: In function
`cvDecRefData': opencv.c:(.text+0xa5c): undefined reference to
`cvFree_' opencv.c:(.text+0xacd): undefined reference to `cvFree_'
/tmp/ccLJWE0c.o: In function `cvGetRow': opencv.c:(.text+0xbc3):
undefined reference to `cvGetRows' /tmp/ccLJWE0c.o: In function
`cvGetCol': opencv.c:(.text+0xbee): undefined reference to `cvGetCols'
/tmp/ccLJWE0c.o: In function `cvReleaseMatND': opencv.c:(.text+0xc01):
undefined reference to `cvReleaseMat' /tmp/ccLJWE0c.o: In function
`cvSubS': opencv.c:(.text+0xd21): undefined reference to `cvAddS'
/tmp/ccLJWE0c.o: In function `cvCloneSeq': opencv.c:(.text+0xd6f):
undefined reference to `cvSeqSlice' /tmp/ccLJWE0c.o: In function
`cvSetNew': opencv.c:(.text+0xdce): undefined reference to `cvSetAdd'
/tmp/ccLJWE0c.o: In function `cvGetSetElem': opencv.c:(.text+0xe61):
undefined reference to `cvGetSeqElem' /tmp/ccLJWE0c.o: In function
`cvEllipseBox': opencv.c:(.text+0xf61): undefined reference to
`cvEllipse' /tmp/ccLJWE0c.o: In function `cvFont':
opencv.c:(.text+0xfb1): undefined reference to `cvInitFont'
/tmp/ccLJWE0c.o: In function `cvReadIntByName':
opencv.c:(.text+0x103f): undefined reference to `cvGetFileNodeByName'
/tmp/ccLJWE0c.o: In function `cvReadRealByName':
opencv.c:(.text+0x10d0): undefined reference to `cvGetFileNodeByName'
/tmp/ccLJWE0c.o: In function `cvReadStringByName':
opencv.c:(.text+0x112a): undefined reference to `cvGetFileNodeByName'
/tmp/ccLJWE0c.o: In function `cvReadByName': opencv.c:(.text+0x115a):
undefined reference to `cvGetFileNodeByName' opencv.c:(.text+0x1170):
undefined reference to `cvRead' /tmp/ccLJWE0c.o: In function
`cvCreateSubdivDelaunay2D': opencv.c:(.text+0x11a3): undefined
reference to `cvCreateSubdiv2D' opencv.c:(.text+0x11cd): undefined
reference to `cvInitSubdivDelaunay2D' /tmp/ccLJWE0c.o: In function
`cvContourPerimeter': opencv.c:(.text+0x1307): undefined reference to
`cvArcLength' /tmp/ccLJWE0c.o: In function `cvCalcHist':
opencv.c:(.text+0x132f): undefined reference to `cvCalcArrHist'
/tmp/ccLJWE0c.o: In function `main': opencv.c:(.text+0x14cd):
undefined reference to `cvCreateImage' opencv.c:(.text+0x1510):
undefined reference to `cvGet2D' opencv.c:(.text+0x159e): undefined
reference to `cvSet2D' opencv.c:(.text+0x15df): undefined reference to
`cvSaveImage' collect2: error: ld returned 1 exit status

另外,当我使用以下方法编译程序时:

gcc opencv.c -o opencv `pkg-config --libs --cflags opencv` -ldl

我仍然得到:

/usr/bin/ld: /tmp/ccMRviO3.o: undefined reference to symbol 'lrint@@GLIBC_2.1'
/usr/bin/ld: note: 'lrint@@GLIBC_2.1' is defined in DSO /lib/libm.so.6 so try adding it to the linker command line
/lib/libm.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

我一直在努力寻找解决方案,但似乎没有什么能解决问题。在 OpenCV 文档中,他们提到了安装所需库的不同方式,但我并不真正理解我必须遵循的步骤。我认为 Fedora 开发了已编译并可以使用的软件包。无论如何,如果这是问题所在,有没有一种简单的方法可以让整个事情顺利进行?

我已经用 Visual Basic 编码 6 年了,但我刚刚开始学习 C 作为我大学教育的一部分;因此我在操作 GCC 方面不是很有经验。:(我会要求你尽可能解释清楚!:)

任何帮助表示赞赏!提前致谢!!!:D

4

1 回答 1

7

尝试添加-lm, 以包含提供的数学库lrint(请参见此处

于 2013-02-03T18:58:37.793 回答