Undefined reference error while compiling a C program on Raspberry Pi

asked 2015-08-03 08:21:55 -0600

alexcase gravatar image

I have been trying, unsuccessfully, to compile my c program for using openCV on the linux-based operating system run on Raspberry Pi, Raspbian. The goal is to interface with the RPi camera, incorporating OpenCV. I have searched similar errors but only found mentions of C++ programs with this specific problem. I do not want this in C++, I want to solve the problem using C programming.

I am compiling a file ending in .c with the following command in the linux LXTerminal:

gcc -o testcode testcode.c

I repeatedly get the follow errors:

/tmp/cclhjysk.o: In function cvDecRefData': testcode.c:(.text+0xe84): undefined reference tocvFree_' testcode.c:(.text+0xf2c): undefined reference to cvFree_' /tmp/cclhjysk.o: In function cvGetRow': testcode.c:(.text+0x10c4): undefined reference to cvGetRows' /tmp/cclhjysk.o: In function cvGetCol': testcode.c:(.text+0x1104): undefined reference to cvGetCols' /tmp/cclhjysk.o: In function cvReleaseMatND': testcode.c:(.text+0x112c): undefined reference to cvReleaseMat' /tmp/cclhjysk.o: In functioncvSubS': testcode.c:(.text+0x12f8): undefined reference to cvAddS' /tmp/cclhjysk.o: In functioncvCloneSeq': testcode.c:(.text+0x1344): undefined reference to cvSeqSlice' /tmp/cclhjysk.o: In function cvSetNew': testcode.c:(.text+0x13cc): undefined reference to cvSetAdd' /tmp/cclhjysk.o: In function cvGetSetElem': testcode.c:(.text+0x149c): undefined reference to cvGetSeqElem' /tmp/cclhjysk.o: In function cvReadIntByName': testcode.c:(.text+0x1584): undefined reference to cvGetFileNodeByName' /tmp/cclhjysk.o: In function cvReadRealByName': testcode.c:(.text+0x1670): undefined reference to cvGetFileNodeByName' /tmp/cclhjysk.o: In function cvReadStringByName': testcode.c:(.text+0x1718): undefined reference to cvGetFileNodeByName' /tmp/cclhjysk.o: In function cvReadByName': testcode.c:(.text+0x1764): undefined reference to cvGetFileNodeByName' testcode.c:(.text+0x1778): undefined reference tocvRead' /tmp/cclhjysk.o: In function cvContourPerimeter': testcode.c:(.text+0x17c0): undefined reference tocvArcLength' /tmp/cclhjysk.o: In function cvCalcHist': testcode.c:(.text+0x1800): undefined reference tocvCalcArrHist' /tmp/cclhjysk.o: In function cvEllipseBox': testcode.c:(.text+0x1908): undefined reference tocvEllipse' /tmp/cclhjysk.o: In function cvFont': testcode.c:(.text+0x1970): undefined reference tocvInitFont' /tmp/cclhjysk.o: In function main': testcode.c:(.text+0x1a0c): undefined reference tocvCreateCameraCapture' testcode.c:(.text+0x1a20): undefined reference to SetCaptureProperty' testcode.c:(.text+0x1a30): undefined reference toSetCaptureProperty' testcode.c:(.text+0x1a40): undefined reference to SetCaptureProperty' testcode.c:(.text+0x1a50): undefined reference toSetCaptureProperty' testcode.c:(.text+0x1a70): undefined reference to cvRetrieveFrame' testcode.c:(.text+0x1a7c): undefined reference tocvGrabFrame' testcode.c:(.text+0x1a90): undefined reference to `cvGrabFramed' collect2: ld returned 1 exit status

I have searched through my RPi for files with mention of cvFree and have been unable to locate them, so I'm thinking that I might be missing a step in the download or excluding a header.

I have the following header files:

stdlib.h

stdio.h

math.h

opencv/cv.h

opencv/highgui.h

opencv/cvaux.h

Note: All the include statements are preceded with a pound/hashtag and the word "include," in addition to being surrounded by "<>" brackets.

I use the following calls (variable types only included in parameters ... (more)

edit retag flag offensive close merge delete

Comments

  • do not use opencv's no more maintained c-api, this is a dead end. to do anything serious with opencv, you must use it's c++ api.
  • you're not linking any required opencv libs like: -lopencv_core -lopencv_imgproc -lopencv_highgui
berak gravatar imageberak ( 2015-08-03 09:02:21 -0600 )edit

berak,

What is the statement needed to include those opencv libs? I'm having difficulty finding these.

alexcase gravatar imagealexcase ( 2015-08-03 09:15:57 -0600 )edit

just add it to your cmdline

berak gravatar imageberak ( 2015-08-03 09:18:29 -0600 )edit

" I do not want this in C++" - you won't have any choice.

berak gravatar imageberak ( 2015-08-03 09:23:21 -0600 )edit

I've got it down to one undefined reference now, with those links to opencv libs. Now, my output is the following:

/usr/bin/ld: /tmp/ccAyCfME.o: undefined reference to symbol 'cvGrabFrame' //usr/local/lib/libopencv_videoio.so.3.0: error adding symbols: DSO missing from command line collect2: ld returned 1 exit status

alexcase gravatar imagealexcase ( 2015-08-03 09:37:20 -0600 )edit

for 2.4, the stuff from videoio is in highgui, too, so remove videoio from your makefile

berak gravatar imageberak ( 2015-08-03 09:41:00 -0600 )edit

I'm using opencv 3.0, and cmake version 2.8, is this the same for this version?

alexcase gravatar imagealexcase ( 2015-08-03 09:54:53 -0600 )edit

I'm still having issues linking to 'cvGrabFrame'... any ideas?

alexcase gravatar imagealexcase ( 2015-08-03 11:30:51 -0600 )edit