OpenCV的安装和使用GCC编译C程序 [英] Install OpenCV and compile C program using GCC

查看:893
本文介绍了OpenCV的安装和使用GCC编译C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个更大的项目我工作的一部分,我需要使用OpenCV库的C程序。我的Fedora 17的32位使用yum OpenCV的安装和OpenCV-DEVEL。我指示preprocessor导入的OpenCV / cv.h和OpenCV / highgui.h,作为必要的头文件。

As part of a bigger project I am working on, I need to use the OpenCV library on a C program. I installed OpenCV and opencv-devel using yum in Fedora 17 32-bit. I instructed the preprocessor to import opencv/cv.h and opencv/highgui.h, as the necessary header files.

正如我所提到的,GCC是用来编译整个C​​ ++项目。然而,似乎有与连接体的问题。

As I've mentioned, gcc is used to compile the whole C project. However, there seems to be a problem with the linker.

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

Whenever I try to compile the project (gcc opencv.c -o opencv), I get a list of errors, similar to:

/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

此外,当我使用编译程序:

Also, when I compile the program using:

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的devel包,其中编译并准备使用。无论如何,如果这是问题,有一个简单的方法,使整个事情的工作?

I've been trying to find a solution, but nothing seems to fix the problem. In the OpenCV Documentation, they mention a different way of installing the libraries needed, but I don't really understand the steps I have to follow. I thought that Fedora devel Packages where compiled and ready to use. Anyway, if this is the problem, is there an easy way to make the whole thing work?

我在Visual Basic中被编码工作6年了,但我刚开始学习C作为我的大学教育的一部分;所以我不是在操纵GCC非常有经验。 :(我想请你尽可能地解释:!)

I've been coding in Visual Basic for 6 years now, but I've just started learning C as part of my University Education; thus I am not very experienced in manipulating GCC. :( I would ask you to be as explanatory as possible! :)

任何帮助AP preciated!提前致谢!!! :D

Any help is appreciated! Thanks in Advance!!! :D

推荐答案

尝试添加 -lm ,以包括数学库,它提供 lrint (见 href=\"http://www.kernel.org/doc/man-pages/online/pages/man3/lrint.3.html\">)

Try adding -lm, to include the math library that provides lrint (see here)

这篇关于OpenCV的安装和使用GCC编译C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆