gpt4 book ai didi

c - 安装OpenCV并使用GCC编译C程序

转载 作者:太空狗 更新时间:2023-10-29 17:23:00 27 4
gpt4 key购买 nike

作为我正在进行的一个更大项目的一部分,我需要在 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

最佳答案

尝试添加 -lm,以包含提供 print 的数学库(参见 here)

关于c - 安装OpenCV并使用GCC编译C程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14676018/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com