Caffe: Error in installing Caffe with OpenCV 3.1.0 on Ubuntu 16.04

Created on 9 Jul 2016  Â·  18Comments  Â·  Source: BVLC/caffe

I want to install CAFFE in ubuntu 16.04 with OpenCV 3.1. I am getting the following error:

$ make all
[ 1%] Built target proto
[ 82%] Built target caffe
[ 82%] Built target finetune_net
[ 82%] Linking CXX executable compute_image_mean
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadDirectory@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFWriteEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFIsTiled@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFOpen@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadEncodedStrip@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFSetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFWriteScanline@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFGetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFScanlineSize@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFNumberOfStrips@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFSetWarningHandler@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFSetErrorHandler@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadEncodedTile@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFReadRGBATile@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFClose@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFRGBAImageOK@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
collect2: error: ld returned 1 exit status
tools/CMakeFiles/compute_image_mean.dir/build.make:134: recipe for target 'tools/compute_image_mean' failed
make[2]: ** [tools/compute_image_mean] Error 1
CMakeFiles/Makefile2:473: recipe for target 'tools/CMakeFiles/compute_image_mean.dir/all' failed
make[1]: *
* [tools/CMakeFiles/compute_image_mean.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Any help will be appreciated.

Most helpful comment

hi all,

I had the same error, but succeed by removing Anaconda form LD_LIBRARY_PATH.
see https://groups.google.com/forum/#!msg/caffe-users/wKYe45FKSqE/HcFMlGS-M8gJ for more details.

Wish this would help anyone who met the same problems:)

All 18 comments

I found that my Makefile have been cluttered by cmake. Fortunately by 'making all' from scratch I did not encounter the mentioned issue.

Recently I forced to use cmake again and the problem came back!

[ 84%] Linking CXX executable compute_image_mean
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadDirectory@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFWriteEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFIsTiled@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFOpen@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadEncodedStrip@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFSetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFWriteScanline@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFGetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFScanlineSize@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFNumberOfStrips@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFSetWarningHandler@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFSetErrorHandler@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadEncodedTile@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFReadRGBATile@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFClose@LIBTIFF_4.0' /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFRGBAImageOK@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference to TIFFReadRGBAStrip@LIBTIFF_4.0' collect2: error: ld returned 1 exit status tools/CMakeFiles/compute_image_mean.dir/build.make:134: recipe for target 'tools/compute_image_mean' failed make[2]: *** [tools/compute_image_mean] Error 1 CMakeFiles/Makefile2:473: recipe for target 'tools/CMakeFiles/compute_image_mean.dir/all' failed make[1]: *** [tools/CMakeFiles/compute_image_mean.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: *** [all] Error 2 sjalal@IPDM-linux-server:~/Softwares/deepLearninig/caffe-master/build$ Linking CXX executable compute_image_mean Linking: command not found sjalal@IPDM-linux-server:~/Softwares/deepLearninig/caffe-master/build$ /usr/local/lib/libopencv_imgcodecs.so.3.1.0: undefined reference toTIFFReadDirectory@LIBTIFF_4.0'^C
sjalal@IPDM-linux-server:~/Softwares/deepLearninig/caffe-master/build$

The caffe config is as following:

`-- ****** Caffe Configuration Summary ******
-- General:
-- Version : 1.0.0-rc3
-- Git : unknown
-- System : Linux
-- C++ compiler : /usr/bin/c++
-- Release CXX flags : -O3 -DNDEBUG -D_FORCE_INLINES -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
-- Debug CXX flags : -g -D_FORCE_INLINES -fPIC -Wall -Wno-sign-compare -Wno-uninitialized

-- Build type : Release

-- BUILD_SHARED_LIBS : ON
-- BUILD_python : ON
-- BUILD_matlab : ON
-- BUILD_docs : ON
-- CPU_ONLY : OFF
-- USE_OPENCV : ON
-- USE_LEVELDB : ON
-- USE_LMDB : ON

-- ALLOW_LMDB_NOLOCK : OFF

-- Dependencies:
-- BLAS : Yes (Atlas)
-- Boost : Yes (ver. 1.58)
-- glog : Yes
-- gflags : Yes
-- protobuf : Yes (ver. 2.6.1)
-- lmdb : Yes (ver. 0.9.17)
-- LevelDB : Yes (ver. 1.18)
-- Snappy : Yes (ver. 1.1.3)
-- OpenCV : Yes (ver. 3.1.0)

-- CUDA : Yes (ver. 7.5)

-- NVIDIA CUDA:
-- Target GPU(s) : Auto
-- GPU arch(s) : sm_50

-- cuDNN : Yes (ver. 5.1.3)

-- Python:
-- Interpreter : /opt/anaconda/anaconda2/bin/python2.7 (ver. 2.7.11)
-- Libraries : /opt/anaconda/anaconda2/lib/libpython2.7.so (ver 2.7.11)

-- NumPy : /opt/anaconda/anaconda2/lib/python2.7/site-packages/numpy/core/include (ver 1.11.0)

-- Matlab:
-- Matlab : Yes (/usr/local/MATLAB/R2015b/bin/mex, /usr/local/MATLAB/R2015b/bin/mexext

-- Octave : No

-- Documentaion:
-- Doxygen : No

-- config_file :

-- Install:

-- Install path : /home/user/Softwares/deepLearninig/caffe-master/build/install

-- Configuring done
-- Generating done
`

Can anyone help me please?
Thanks.

I met the same problem, I checked that the opencv build without tiff=ON, so I turn it on and remake opencv, and then make the caffe successfully, hope that can help you.

What is tiff = ON? How do you do that?

I forget the details. The tiff is one module in opencv, we set the tiff ON to build opencv with tiff support. I think it's the main idea. Then when you build caffe with opencv, it may not raise issues.

hi all,

I had the same error, but succeed by removing Anaconda form LD_LIBRARY_PATH.
see https://groups.google.com/forum/#!msg/caffe-users/wKYe45FKSqE/HcFMlGS-M8gJ for more details.

Wish this would help anyone who met the same problems:)

Thank you Roll920! I've been working on this problem for hours but removing Anaconda from LD_LIBRARY_PATH fixed everything immediately.

From https://github.com/BVLC/caffe/blob/master/CONTRIBUTING.md:

_Please do not post usage, installation, or modeling questions, or other requests for help to Issues._
Use the caffe-users list instead. This helps developers maintain a clear, uncluttered, and efficient view of the state of Caffe.

@leo2105,

I found TIFF=off in my CMakeCache.txt file.

I successfully installed Open CV after setting it to ON.

I was installing only openCV. Not caffe.

My environment: Ubuntu 16.04

Thank you LuoBo! @Roll920

None of the above workarounds have helped me get past this problem; not even disabling OpenCV in the Makefile.config.

make upgrade_net_proto_text upgrade_net_proto_binary
[  1%] Built target caffeproto
[ 98%] Built target caffe
[ 98%] Linking CXX executable upgrade_net_proto_text
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::AssignDescriptors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFWriteEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFOpen@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::DebugString[abi:cxx11]() const'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFSetField@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::MessageLite::ParseFromString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::GetTypeName[abi:cxx11]() const'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::OnShutdownDestroyString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `_TIFFfree@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::fixed_address_empty_string[abi:cxx11]'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFGetField@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFNumberOfStrips@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::Message::InitializationErrorString[abi:cxx11]() const'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::NameOfEnum[abi:cxx11](google::protobuf::EnumDescriptor const*, int)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFWriteDirectory@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `_TIFFmalloc@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFReadEncodedTile@LIBTIFF_4.0'
../lib/libcaffe.so.1.0.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFReadRGBATile@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFReadScanline@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFClose@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFRGBAImageOK@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so.3.4.1: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
collect2: error: ld returned 1 exit status

I am not sure how to keep /usr/local/lib/libopencv_imgcodecs.so out of the link. That could solve my problem.

But it's also unclear why /usr/local/lib/libopencv_imgcodecs.so is referencing the TIFF symbols if they don't exist. Doesn't this indicate that that shared object is broken, or that the dependencies aren't properly listed somewhere?

This yak has taken me hours to shave and I'm nowhere near a solution.

_Update_ I notice these reference libtiff 4 but…

$ dpkg -l|grep libtiff
ii  libtiff-tools                          4.0.6-1ubuntu0.4                           amd64        TIFF manipulation and conversion tools
ii  libtiff5:amd64                         4.0.6-1ubuntu0.4                           amd64        Tag Image File Format (TIFF) library
ii  libtiff5-dev:amd64                     4.0.6-1ubuntu0.4                           amd64        Tag Image File Format library (TIFF), development files
ii  libtiffxx5:amd64                       4.0.6-1ubuntu0.4                           amd64        Tag Image File Format (TIFF) library -- C++ interface

Looks like I might have to reinstall libopencv from source… trying that

_Update_ Hm, I notice this in the build log for new libopencv build ... what package could this correspond to??

-- Found TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (found version "4.0.6")

In any case, the libopencv build fails because this file is missing, but afaict it should be in package libgl1-mesa-glx (https://packages.ubuntu.com/search?suite=xenial&arch=any&mode=filename&searchon=contents&keywords=libGL.so):

make[3]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/libGL.so', needed by 'lib/libopencv_core.so.2.4.9'.  Stop.
...
ls: cannot access '/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0': No such file or directory

But:

$ sudo apt-get install -f libgl1-mesa-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libgl1-mesa-dev is already the newest version (18.0.5-0ubuntu0~16.04.1).
The following packages were automatically installed and are no longer required:
  libaio1 librados2 librbd1 librdmacm1
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

This seemed to fix the missing file:

(tensorflow_p27) ubuntu@ip-172-31-41-235:~/libopencv-dev-build/opencv-2.4.9.1+dfsg$ sudo apt-get install --reinstall libgl1-mesa-glx
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 132 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libgl1-mesa-glx amd64 18.0.5-0ubuntu0~16.04.1 [132 kB]
Fetched 132 kB in 0s (9,541 kB/s)
(Reading database ... 246401 files and directories currently installed.)
Preparing to unpack .../libgl1-mesa-glx_18.0.5-0ubuntu0~16.04.1_amd64.deb ...
Unpacking libgl1-mesa-glx:amd64 (18.0.5-0ubuntu0~16.04.1) over (18.0.5-0ubuntu0~16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Setting up libgl1-mesa-glx:amd64 (18.0.5-0ubuntu0~16.04.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
(tensorflow_p27) ubuntu@ip-172-31-41-235:~/libopencv-dev-build/opencv-2.4.9.1+dfsg$ ls -l /usr/lib/x86_64-linux-gnu/mesa/
total 468
-rw-r--r-- 1 root root     31 Jun 14 18:30 ld.so.conf
lrwxrwxrwx 1 root root     14 Jun 14 18:30 libGL.so -> libGL.so.1.2.0
lrwxrwxrwx 1 root root     14 Jun 14 18:30 libGL.so.1 -> libGL.so.1.2.0
-rw-r--r-- 1 root root 471680 Jun 14 18:31 libGL.so.1.2.0

_Update_ Rebuilding libopencv-dev Debian package (in an attempt to fix the libtiff linkage issue from v5 to v4?) failed as well, with the following baffling report:

dpkg-shlibdeps: error: no dependency information found for /usr/lib/libGL.so.1 (used by debian/libopencv-core2.4v5/usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.9)
Hint: check if the library actually comes from a package.

So how did the libopencv package get created in the first place?

I have to abandon this for now and try a different environment. The above efforts were on an AWS p2.xlarge instance with AMI Deep Learning AMI. In this environment libtiff4 packages simply aren't available.

ubuntu@ip-172-31-41-235:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"

Thanks @Roll920 I had to remove anaconda from PATH too.

conda remove libtiff

When I make mattest,I met the follow problem.
Invalid MEX-file
'/home/caffe/matlab/+caffe/private/caffe_.mexa64':
/usr/local/lib/libopencv_imgcodecs.so.3.4: undefined symbol:
ZN2cv6detail17check_failed_autoEmmRKNS0_12CheckContextE.
Error in caffe.set_mode_cpu (line 5)
caffe('set_mode_cpu');
Error in caffe.run_tests (line 6)
caffe.set_mode_cpu();

Anyone knows how to solve it? Thanks a lot @Roll920
ubuntu
matlab:R2018b
cuda:10.0
opencv:3.4.7
gcc/g++:5.5

THE ULTIMATE SOLUTION IS THAT WE SHOULD PREVENT USING caffe, most stupid package ever exist in this world.

100% agree

worked in the past and was a good pioneer in AI frameworks, but it has not been too developed currently.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

greatgao picture greatgao  Â·  3Comments

FreakTheMighty picture FreakTheMighty  Â·  3Comments

OpenHero picture OpenHero  Â·  3Comments

sdemyanov picture sdemyanov  Â·  3Comments

dfotland picture dfotland  Â·  3Comments