How to compile old OpenCV code using 2.4.9
I'm trying to compile some old code of OpenCV that I found here.
However, the code seems quite old. I was able to compile it by adding the new headers
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
to the files global.h
and IntImage.h
, with addition of
#include <opencv/cv.h>
to the IntImage.h
.
Note that I don't want to port all the code to OpenCV 2.4.9 right now, but rather to make it work. Thus, once that compile I still obtain the error:
UIUCscene.o: In function
IntImage<double>::Load(std::string const&)': UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x20): undefined reference to
cvLoadImage' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x53): undefined reference tocvCreateImage' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x6b): undefined reference to
cvCvtColor' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x78): undefined reference tocvReleaseImage' UIUCscene.cpp:(.text._ZN8IntImageIdE4LoadERKSs[_ZN8IntImageIdE4LoadERKSs]+0x73c): undefined reference to
cvReleaseImage' collect2: error: ld returned 1 exit status make: * [place] Error 1
It seems to me that the problem is linking. However, I'm not sure where the problem is. In the Makefile
the flags are set using pkg-config --cflags opencv
, and the same for retrieving the libraries. The result of running pkg-config --libs opencv
is
/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so /usr/lib/x86_64-linux-gnu/libXext.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so -ltbb -lrt -lpthread -lm -ldl
as you can see, the legacy library is there.
What am I missing? Any help or pointers are appreciated.
These are all linking errors. You need to specify the legacy linking libraries. Somehow, they are not being picked.
Actually before you go and dig deeper into fixing all these problems with temporary solutions, try defining how long it would take to replace stuff to the new C++ interface. That will guarantee future working of the complete code. There are like 8 sourcecode files, it should be possible to fix the code to the new interface in a day or so!
As to solving your problem, make sure your include directories know the opencv/ and the opencv2/ header file location!
For the linking I'm using
pkg-config --cflags opencv
andpkg-config --libs opencv
. The latter includes the legacylibopencv_legacy.so
. But still gives me error. I build OpenCV myself, should I need some special flag to build legacy?Just a thought.
so
s are shared objects and the way you have them specified, the code should compile. But do you also happen to have static libraries (extensionlib
)? If so, can you try to manually link against those?@unxnut I don't have other libraries. Just the ones I posted using the
pkg-config
. I don't understand why is not finding the symbols. Searching the web I found that there were some errors with thepkg-config
of previous OpenCV releases. Not sure if that is the problem though.How about trying to link manually against the shared objects?