Reputation: 13
i have to do a program using C Language and OpenCV Libreries for a project, I followed the guide for the installation for MACOSX on this site: OpenCV Installation
I used Mac Port for the Istallation.
I use Eclipse to program, Now when i try to compile this program, i get a Build Error and i think that it depends to CalcOpticalFlowFarneback() Function.
This is the code:
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <time.h>
int main(){
CvCapture* webcam = cvCreateCameraCapture(0);
IplImage*prev=NULL;
IplImage*next=NULL;
char scelta;
/*INIZIALIZZAZIONE FUNZIONE RAND*/
srand(time(NULL));
double pyr_scale=0.5;
int levels=1;
int winsize=3;
int iterations=10;
int poly_n=5;
double poly_sigma=1.1;
int flags=0;
sleep(2);
if (!webcam){
/* Exit with an error */
puts("Attenzione! si è verificato un Errore in Fase di Attivazione della WebCam. Preghiamo di Riprovare!");
return -1;
}
while (1) {
prev = cvQueryFrame(webcam);//primi 8-bit single-channel immagine in ingresso
next = cvQueryFrame(webcam);// immagine secondo ingresso della stessa dimensione e lo stesso tipo prev.
CvSize isize = cvSize(80,80);
IplImage *flow = cvCreateImage(isize, IPL_DEPTH_32F, 1); //immagine computerizzata che ha le stesse dimensioni e tipo CV_32FC2 prev
if ((prev) && (next)) {
cvCalcOpticalFlowFarneback(prev,next,flow,pyr_scale,levels,winsize,iterations,poly_n,poly_sigma,flags);
scelta=cvWaitKey(20);
if((char)scelta == 27){
break;
}
}
}
cvDestroyWindow("VIDEO SORVEGLIANZA");
cvReleaseCapture(&webcam);
return 0;
}
and this is the error Log:
Undefined symbols for architecture x86_64: "_cvCalcOpticalFlowFarneback", referenced from:_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [cattura_foto] Error 1
And I want to specify that if i remove the cvCalcOpticalFlowFarneback Function i do not have any problems.
Thank you,
manu.web
Upvotes: 1
Views: 1837
Reputation: 57388
"undefined symbol" means that you have not linked against the proper library, or you have, but the library is for the wrong architecture (e.g. a 32-bit library while your machine is 64-bit).
You need to check the linking flags and paths, and the library installation path.
If you can get the linker log in Eclipse, and/or the command line that got passed to the linker, you can repeat the linking command from a terminal and see if you get a more helpful message (such as "library not found"). Or you can try running the make
command from the terminal and do the same.
Editing the Makefile, you might find that some commands are prepended with the "@" symbol, which prevents them from being output (their output is visible, the command itself is not). You can usually safely remove the @'s and get a more verbose output.
Another possibility is that there is a name mangling error, and the "_" prefix to the function should not be there. I am not too familiar with Eclipse though, so I can't follow you there. But see e.g. http://www.eclipse.org/forums/index.php/m/783606/ ; you might have built OpenCV with the wrong options, so that now it is not compatible with your code. Which is strange, seeing as how you call other OpenCV functions without problems; but maybe you built OpenCV in two steps?
In general (this is not limited to OpenCV!) you will have a build command such as
gcc -I/usr/local/include/opencv -L/usr/local/lib main.c -o Cattura_foto2 \
-lopencv_core.2.4.3 \
-lopencv_imgproc.2.4.3 \
-lopencv_highgui.2.4.3 \
-lopencv_gpu.2.4.3
and an error complaining of an undefined symbol:
Undefined symbols for architecture x86_64: "_cvCalcOpticalFlowFarneback"
This means that you are linking with the libraries openvc_core.2.4.3 etc. and the linker cannot find the symbol "_cvCalcOpticalFlowFarneback".
Locate those libraries on your computer, and run (from Terminal) the following command against all the libraries you found. Note: your path will probably be different. I have /usr/lib64.
for lib in /usr/lib64/libopencv_*; do
echo "Examining $lib..."
strings $lib | grep -i cvCalcOpticalFlowFarneback
done
You ought to see something like:
Examining /usr/lib/libopencv_pippo_pluto...
Examining /usr/lib/libopencv_blah_blah...
...
Examining /usr/lib64/libopencv_video.so...
cvCalcOpticalFlowFarneback
cvCalcOpticalFlowFarneback
Examining /usr/lib64/libopencv_video.so.2.4...
cvCalcOpticalFlowFarneback
cvCalcOpticalFlowFarneback
Examining /usr/lib64/libopencv_video.so.2.4.3...
cvCalcOpticalFlowFarneback
cvCalcOpticalFlowFarneback
The reason for the multiple matches is that libraries exist in multiple symbolic copies.
To be sure, let's inspect the library:
nm -D /usr/lib64/libopencv_video.so.2.4 | grep Farneback
0000000000027e50 T cvCalcOpticalFlowFarneback
Now we know two important things:
cvCalcOpticalFlowFarneback
. Your GCC is complaining it doesn't find the symbol _cvCalcOpticalFlowFarneback
, with an underscore. You either built the library incorrectly or you are missing a -fno-leading-underscore
option to GCC.But if that were the case, no OpenCV2 symbols at all would be recognized. So, I'm betting on #2:
Let me know how it goes - and in bocca al lupo.
Upvotes: 2