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

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!!)

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.

Related

Compile a C++ program (LANShare)

I'm having problems compiling LANShare's sourcecode.
I need to compile this program because i need to use it on a 32-bit unix machine and there's no .deb or appimage release file.
This is LANShare.
As you can see there's no config file and i don't know how i can proceed with compilation.
I compiled from source many times but here there's no Readme nor instructions, then I opened an issue but there's no response yet.
Found a solution, thanks to n. 1.8e9-where's-my-share m.
Theese instructions should be valid for any Debian 10 install.
To install qt tools:
sudo apt install qt5-qmake qt5-default
then to compile:
qmake -o Makefile LANShare.pro
make
within the README.md file there is:
You can download the Ubuntu package or linux AppImage or Windows executable from the release page.
https://github.com/abdularis/LAN-Share/releases
Using .deb (Ubuntu/Debian)
download the latest version, for example lanshare_1.2.1-1_amd64.deb then open a terminal, navigate to directory where the downloaded package is located and type
$ sudo dpkg -i ./lanshare_1.2.1-1_amd64.deb

RedHawk building from source --- locate the code installing uhd3.5.3

I am trying to build from source for RedHawk installation and trying to replace uhd3.5.3 with a higher version of uhd for USRP_UHD module. I saw USRP_UHD source code, but found nowhere for uhd3.5.3 source code. I am guessing it might simply use "yum install ..." to download and install uhd host code and suporting libraries. Does anybody know where this code is located in redhawk_src_2.0 package? Or is there an efficient way in linux to search for this among all the files in redhawk_src_2.0 package?
Thanks in advance!
UHD is the USRP Harware driver softwware from Ettus Research. The UHD is distributed from:
http://files.ettus.com/binaries/uhd_stable/
Version 3.5.3 is here:
http://files.ettus.com/binaries/uhd_stable/uhd_003.005.003-release/
The current release is 3.9.2:
http://files.ettus.com/binaries/uhd_stable/uhd_003.009.002-release/
Hopefully this helps. I wasn't 100% sure what you are asking for.
First, clone the uhd library:
git clone git://github.com/EttusResearch/uhd.git
Then checkout the 3.9.2 tag:
git checkout release_003_009_002
Using the instructions from Ettus (http://files.ettus.com/manual/page_build_guide.html), install the dependencies listed under the Fedora section:
sudo yum -y install boost-devel libusb1-devel python-mako doxygen python-docutils cmake make gcc gcc-c++
Next, generate the Makefiles with CMake:
cd <uhd-repo-path>/host
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/uhd ../
I recommend using an alternate install prefix at first to preserve the 3.5.3 version, just in case, but if you don't want to, just run:
cmake ../
instead of the longer command with the -DCMAKE_INSTALL_PREFIX flag. (Note: I couldn't get cmake to find the installed boost version, so you may have to do some other research on that since it is probably a whole different stackoverflow post in and of itself)
Now build and install the uhd library:
make
make test
sudo make install
Now that the library is installed, you should edit the USRP_UHD/cpp/configure.ac so that the PKG_CONFIG_PATH points to your install prefix (either the one specified in the flag above, or if you did the default, just leave it, as it should already be pointing to /usr/local/lib/pkgconfig). Also in the configure.ac file, make sure to change the uhd version number to 3.9.2.
Now you should be able to rebuild the USRP_UHD Device:
./reconf && ./configure && make install
I don't guarantee that the Device will build against the new version of the uhd library, that will depend on what (if anything) has been deprecated an removed from the library between the supported version and the newest one.
Finally, if you get through all of those steps successfully and if you specified a non-standard install prefix, you will have to add this prefix to either the LD_LIBRARY_PATH or an /etc/ld.so.conf.d/ script in order for the Device to correctly execute.
Clarification - you can follow the Redhawk manual appendix B for building Redhawk from source AFTER installing UHD v3.9.3 from source as per pwolframs instructions. The UHD v3.5.3 is not packaged with the Redhawk source code, only the Redhawk RPM, disregard all those RPMs when building UHD and Redhawk from source.

Error with homebrew + opencv + libpng

On Mac OS Maverick I have installed OpenCV with a brew install opencv.
I created a simple program (copied from this tutorial). Compilation worked fine but when running the executable I get the following error:
dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib
Referenced from: /usr/local/lib/libopencv_highgui.2.4.dylib
Reason: Incompatible library version: libopencv_highgui.2.4.dylib requires version 33.0.0 or later, but libpng16.16.dylib provides version 32.0.0
Trace/BPT trap: 5
I checked that libpngwas properly installed via brew install libpng and ran a brew upgrade to make sure everything was up-to-date.
Running locate libpng16.dylib returns:
/Applications/GIMP.app/Contents/Resources/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.10/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.12/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.13/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.15/lib/libpng16.16.dylib
/usr/local/lib/libpng16.16.dylib
Any idea?
The best solution is to fully uninstall libpng and re-install it:
$ sudo brew uninstall libpng
$ sudo rm '/usr/local/bin/libpng-config'
$ for i in `brew link --overwrite --dry-run libpng`; do sudo rm $i; done
$ sudo brew install libpng
If you need to install opencv:
$ sudo brew tap homebrew/science
$ sudo brew install opencv
Homebrew should ensure that you the correct dependencies install. However, it's possible that you have more than one version of libpng16 installed at different paths. Have a look in...
/usr/lib
/opt/local/lib
If you find any versions of the library in these locations then they may be causing the wrong one to be loaded when your program starts. As a quick fix you can try typing DYLD_LIBRARY_PATH=/usr/local/lib before your program name on the command line. In the longer term you may need to remove the conflicting versions altogether.
This answer is for OSX users who installed through Conda, more specifically the conda-forge channel (I'm not sure about others).
Conda ends up installing its own libpng in the environment and you can update it with conda upgrade libpng.
I guess this is basically a bug with the opencv recipe on conda-forge.

Boost C++ library Version Issue

After downloading and untar the file "boost_1_56_0.tar.gz", I have installed Boost C++ library version "boost_1_56_0" in CentOS Linux.
I have run the following commands to install:
sudo ./bootstrap.sh --prefix=/usr/local
sudo ./b2 install.
I also added two paths to the PATH variable:
export PATH=$PATH:/usr/local/include/:/usr/local/lib/
It has been successfully installed. However when I checked the version it showed different version:
$ cat /usr/include/boost/version.hpp | grep "BOOST_LIB_VERSION"
#define BOOST_LIB_VERSION "1_33_1"
I have tried to install boost_1_55_0 as well in another folder but unfortunately still it shows version 1_33_1.
Can anyone here tell me how I can fix this issue?
Because of this issue, I am unable to configure Graph_tool; it shows following error:
checking for boostlib >= 1.53.0... configure: error: We could not detect the boost libraries (version 1.53 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation>
Your bootstrap path is /usr/local. Make sure your BOOST_ROOT points to your bootstrapped folder, not the installed 1.33 version.

How do I install the OpenSSL libraries on Ubuntu?

I'm trying to build some code on Ubuntu 10.04 LTS that uses OpenSSL 1.0.0. When I run make, it invokes g++ with the "-lssl" option. The source includes:
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/des.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
I ran:
$ sudo apt-get install openssl
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
But I guess the openssl package doesn't include the library. I get these errors on make:
foo.cpp:21:25: error: openssl/bio.h: No such file or directory
foo.cpp:22:28: error: openssl/buffer.h: No such file or directory
foo.cpp:23:25: error: openssl/des.h: No such file or directory
foo.cpp:24:25: error: openssl/evp.h: No such file or directory
foo.cpp:25:25: error: openssl/pem.h: No such file or directory
foo.cpp:26:25: error: openssl/rsa.h: No such file or directory
How do I install the OpenSSL C++ library on Ubuntu 10.04 LTS?
I did a man g++ and (under "Options for Linking") for the -l option it states: " The linker searches a standard list of directories for the library..." and "The directories searched include several standard system directories..." What are those standard system directories?
You want to install the development package, which is libssl-dev:
sudo apt-get install libssl-dev
Run:
apt-get install libssl-dev
All of these answers are very outdated and from when the package was still being developed. You can now just use the "normal" command listed below:
sudo apt install openssl
Edit: OP's question is poorly worded... after all, OpenSSL is a library itself, so I read his question too quickly before answering. The command above installs "normal" OpenSSL.
Toward the bottom of his question he mentions that make fails, suggesting he is compiling the package manually. And yes, even if you download the TAR ball, it will include all of the openssl and libssl files, which you can then make from.
What OP is really asking for is the OpenSSL Development Library, in which case you can first install OpenSSL using the above command, and then run this afterwards:
sudo apt install libssl-dev
More info: https://linuxtect.com/how-to-install-openssl-libraries-on-ubuntu-debian-mint/
I found a detailed solution here: Install OpenSSL Manually On Linux
From the blog post...:
Steps to download, compile, and install are as follows (I'm installing version 1.0.1g below; please replace "1.0.1g" with your version number):
Step – 1 : Downloading OpenSSL:
Run the command as below :
$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
Also, download the MD5 hash to verify the integrity of the downloaded file for just varifacation purpose. In the same folder where you have downloaded the OpenSSL file from the website :
$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz.md5
$ md5sum openssl-1.0.1g.tar.gz
$ cat openssl-1.0.1g.tar.gz.md5
Step – 2 : Extract files from the downloaded package:
$ tar -xvzf openssl-1.0.1g.tar.gz
Now, enter the directory where the package is extracted like here is openssl-1.0.1g
$ cd openssl-1.0.1g
Step – 3 : Configuration OpenSSL
Run below command with optional condition to set prefix and directory where you want to copy files and folder.
$ ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
You can replace “/usr/local/openssl” with the directory path where you want to copy the files and folders. But make sure while doing this steps check for any error message on terminal.
Step – 4 : Compiling OpenSSL
To compile openssl you will need to run 2 command : make, make install as below :
$ make
Note: check for any error message for verification purpose.
Step -5 : Installing OpenSSL:
$ sudo make install
Or without sudo,
$ make install
That’s it. OpenSSL has been successfully installed. You can run the version command to see if it worked or not as below :
$ /usr/local/openssl/bin/openssl version
OpenSSL 1.0.1g 7 Apr 2014
How could I have figured that out for
myself (other than asking this
question here)? Can I somehow tell
apt-get to list all packages, and grep
for ssl? Or do I need to know the
"lib*-dev" naming convention?
If you're linking with -lfoo then the library is likely libfoo.so. The library itself is probably part of the libfoo package, and the headers are in the libfoo-dev package as you've discovered.
Some people use the GUI "synaptic" app (sudo synaptic) to (locate and) install packages, but I prefer to use the command line. One thing that makes it easier to find the right package from the command line is the fact that apt-get supports bash completion.
Try typing sudo apt-get install libssl and then hit tab to see a list of matching package names (which can help when you need to select the correct version of a package that has multiple versions or other variations available).
Bash completion is actually very useful... for example, you can also get a list of commands that apt-get supports by typing sudo apt-get and then hitting tab.
Another way to install openssl library from source code on Ubuntu, follows steps below, here WORKDIR is your working directory:
sudo apt-get install pkg-config
cd WORKDIR
git clone https://github.com/openssl/openssl.git
cd openssl
./config
make
sudo make install
# Open file /etc/ld.so.conf, add a new line: "/usr/local/lib" at EOF
sudo ldconfig
You want the openssl-devel package.
At least I think it's -devel on Ubuntu. Might be -dev. It's one of the two.
As a general rule, when on Debian or Ubuntu and you're missing a development file (or any other file for that matter), use apt-file to figure out which package provides that file:
~ apt-file search openssl/bio.h
android-libboringssl-dev: /usr/include/android/openssl/bio.h
libssl-dev: /usr/include/openssl/bio.h
libwolfssl-dev: /usr/include/cyassl/openssl/bio.h
libwolfssl-dev: /usr/include/wolfssl/openssl/bio.h
A quick glance at each of the packages that are returned by the command, using apt show will tell you which among the packages is the one you're looking for:
~ apt show libssl-dev
Package: libssl-dev
Version: 1.1.1d-2
Priority: optional
Section: libdevel
Source: openssl
Maintainer: Debian OpenSSL Team <pkg-openssl-devel#lists.alioth.debian.org>
Installed-Size: 8,095 kB
Depends: libssl1.1 (= 1.1.1d-2)
Suggests: libssl-doc
Conflicts: libssl1.0-dev
Homepage: https://www.openssl.org/
Tag: devel::lang:c, devel::library, implemented-in::TODO, implemented-in::c,
protocol::ssl, role::devel-lib, security::cryptography
Download-Size: 1,797 kB
APT-Sources: http://ftp.fr.debian.org/debian unstable/main amd64 Packages
Description: Secure Sockets Layer toolkit - development files
This package is part of the OpenSSL project's implementation of the SSL
and TLS cryptographic protocols for secure communication over the
Internet.
.
It contains development libraries, header files, and manpages for libssl
and libcrypto.
N: There is 1 additional record. Please use the '-a' switch to see it
Go to the official website and download the source code for the version you need
Then unzip the update package and execute the following command
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl -Wl,-rpath,/usr/local/ssl/lib shared
Because the default is to generate only static libraries, if you want dynamic libraries, add the "shared" option
make && make install
sudo apt-get install libcurl4-openssl-dev