Ullesh Chavadi M
Ullesh Chavadi M

Reputation: 31

How to install 2 Opencv versions on one Ubuntu machine and How to activate one at a time for compilation?

I have installed two versions of opencv in my ubuntu12.04 machine , one in /usr/local/ (opencv3.0.0) and another in /usr/ (opencv2.4.9). To activate particular version i am using these commands in terminals. Example :To activate opencv2.4.9,

sudo sh -c 'echo "/usr/" > /etc/ld.so.conf.d/opencv.conf' (shell script)
sudo ldconfig
export PKG_CONFIG_PATH=/usr/lib/pkgconfig

After executing these commands version is changing. Checked with command, pkg-config --modversion opencv. Then i compiled my code and checked used libraries, Using ldd command, It is listing opencv3.0.0 version not opencv2.4.9.

Please help correct way of switching opencv versions.

Thanks in advance

Upvotes: 2

Views: 1958

Answers (2)

You still can install both versions and append on the environment path the path of the version you want to use.

If you don't know how to change system path check this ( How to permanently set $PATH on Linux? )

Upvotes: 1

Ullesh Chavadi M
Ullesh Chavadi M

Reputation: 31

Thank you,

I found a solution for this problem, but I am not sure the solution what iIfound is correct way or not. But it is working fine for me.

When we install two versions of opencv in different locations,we will found two opencv.pc file in {path}/lib/pkgconfig/opencv.pc. In above example opencv2.4.9's opencv.pc file is in this path usr/lib/pkgconfig/opencv.pc. and opencv3.0.0's opencv.pc file is in this path /usr/local/lib/pkgconfig/opencv.pc When we compile a code it will search in both location for opencv.pc configuration file, it will use which ever first it is getting, neglecting second one.
so if want compile code with particular version we need to remove this opencv.pc file from that location.

If you want to use opencv2.4.9 remove(or rename)opencv.pc from opencv3.0.0's lib/pkgconfig/ location. Again if want activate opencv3.0.0 add opencv.pc to its lib/pkgconfig/ location and remove opencv2.4.9's opencv.pc file from /lib/pkgconfig/opencv.pc.

If somebody knows a better way to do this, please comment.

Upvotes: 1

Related Questions