I just spent a frustratingly long time getting openCV to link properly in Ubuntu 12.04 and thought I would share what I learned for the benefit of others.
OpenCV is now available in the Ubuntu repositories as
sudo apt-get install libopencv-dev
which is great, but I believe (please correct me if I'm wrong) that this version of opencv has a different naming convention for the libraries. The main difference is that in c++ the include line should read
#include "opencv2/opencv.hpp"
That will get your code compiling to object but not linking. The other difference is that the static libraries have also been renamed from libcv* to libopencv*. For example binaries can now be located at
/usr/lib/libopencv_core.so
/usr/lib/libopencv_highgui.so
.
.
.
To fix this I needed to explicitly tell the linker about the new library names by changing my compiler command to
g++ main.cpp -lopencv_core -lopencv_highgui ...
Or in CMake
target_link_libraries(main opencv_core opencv_highgui ...)
I hope this helps. And if anyone knows more than me I'd love to find out what's going on here.
-Mike
Personally, I'm using 'pkg-config' to get the compilation flags.
g++ `pkg-config --cflags opencv` main.c `pkg-config --libs opencv` -o main
Example of main:
#include <stdio.h>
#include <cv.h>
int main(void)
{
printf("%s\r\n", CV_VERSION);
printf("%u.%u.%u\r\n", CV_MAJOR_VERSION, CV_MINOR_VERSION, CV_SUBMINOR_VERSION);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With