CathIAS
CathIAS

Reputation: 325

How to make builds use the newer version of two installed OpenCVs?

I have just installed the newest OpenCV from source. After the installation I found that OpenCV was already installed on my computer. Now I have a /usr/include/opencv and a /usr/include/opencv2 existing together.

When I was trying to compile an example from the newest version, it automatically went to the directory opencv2 to find the header files. Obviously some examples in the new version require header files that only exist in opencv but not in opencv2.

I checked the version being used as follows.

$ pkg-config --modversion opencv
2.4.8

How can I clean the old version and set the environmental variables such that the newer version is used instead?


Thanks for pointing it out. I didn't realize that both /opencv and /opencv2 exist at the same time in normal installations. So these folders are irrelevant.

Here's what I did to install OpenCV. I followed this tutorial on my newly installed ubuntu 14.04: http://www.bogotobogo.com/OpenCV/opencv_3_tutorial_ubuntu14_install_cmake.php

I git cloned and did a full make install. I thought the git source was of version 3.0.0, am I wrong on that?

(Sorry for the late edit and thanks so much for your help!!)

Upvotes: 2

Views: 1536

Answers (1)

moooeeeep
moooeeeep

Reputation: 32512

To reproduce your problem, I have just installed OpenCV from the Ubuntu package repository:

$ sudo aptitude install libopencv-dev

Which put include files to these places:

/usr/include/opencv
/usr/include/opencv2

I then downloaded and installed OpenCV from this place: http://opencv.org/

$ cd Downloads/opencv-3.0.0
$ mkdir build
$ cd build
$ cmake ..
[lots of configuration related output ...]
$ make -j7
[lots of build related output ...]
$ sudo make install
[lots of installation related output ...]

pkg-config now finds the newer version:

$ pkg-config --modversion opencv
3.0.0

And the includes are located here:

/usr/local/include/opencv
/usr/local/include/opencv2

You shouldn't have a problem, given you want to use the later installed version. (Are you sure you did properly install the custom build: sudo make install?)


You might want to remove the older version:

$ sudo aptitude remove libopencv-dev

However, you should make sure that you don't remove dependencies your custom build relies on (zlib, libjpeg, libtiff, pibpng, ...).


That being said, pkg-config gives you the details from the opencv.pc file it finds last.

These are the available files:

$ locate opencv.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc
/usr/local/lib/pkgconfig/opencv.pc

The latter belongs to the newer version (build from source), the first belongs to the older version (package install).

This is the search path:

$ pkg-config --variable pc_path pkg-config
/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

Given this order of the entries in the search path, you get the newer version via pkg-config.

Upvotes: 3

Related Questions