Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking error with `libopencv_highgui.so` under Ubuntu 14.04, strange result with `libtiff.so.5`

Problem

I'm compiling the deep learning library Caffe in Ubuntu 14.04(64 bit).

OpenCV(Version: 2.4.8+dfsg1-2ubuntu1) is installed from ubuntu packages server with :

sudo apt-get install libopencv-dev

Compile Caffe with CMake 2.8.

Linking error:

Linking CXX executable caffe-

/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.8: undefined reference to `TIFFOpen@LIBTIFF_4.0'

Infomation

It seems some symbols of TIFF library were not found. I made some effort to find the reason(without luck). Here's some infomation about the libraries.

TIFF library linked by libopencv_highgui.so.2.4.8

$ ldd libopencv_highgui.so.2.4.8 | grep tiff

libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f978313b000)

Import symbols of libopencv_highgui.so.2.4.8

$ readelf -s libopencv_highgui.so.2.4.8 |grep TIFFOpen

62: 0000000000000000 0 FUNC GLOBAL DEFAULT UND TIFFOpen@LIBTIFF_4.0 (9)

Note: There is one single @ in the symbol names.

$ nm -D libopencv_highgui.so.2.4.8| grep TIFFOpen

U TIFFOpen

Export symbols of libtiff.so.5:

$ nm -D /usr/lib/x86_64-linux-gnu/libtiff.so.5

0000000000000000 A LIBTIFF_4.0

...

00000000000429f0 T TIFFOpen

...

$ readelf -s /usr/lib/x86_64-linux-gnu/libtiff.so.5|grep TIFFOpen

99: 00000000000429f0 239 FUNC GLOBAL DEFAULT 12 TIFFOpen@@LIBTIFF_4.0

Note: There are two @(@@) in the symbol names.

My confusion

  1. Is it because libtiff.so.5 has @@ in the symbol names instead of @ that made the linking error

    libopencv_highgui.so.2.4.8: undefined reference to 'TIFFIsTiled@LIBTIFF_4.0'

  2. What's the difference between @ and @@ in symbol names?
  3. What's the meaning of the suffix LIBTIFF_4.0 of symbols names in libtiff.so.5?
  4. Many people said it's because OpenCV need libtiff4-dev which is not provided by Ubuntu 14.04. Then why the Ubuntu guys put a broken package on the package server.
  5. How to solve the linking problem?

I'm not a profession on compiling and linking. Sorry for such a long post. Just what to provide enough infomation for you guys to help me. Appreciate for any suggestions.

P.S. If you need more infomation of those libs, feel free to say in the comment.

like image 919
nn0p Avatar asked Mar 26 '15 06:03

nn0p


4 Answers

I had similiar problems and it was due to Anaconda messing up

I simply had to execute the following command:

conda remove libtiff

I installed opecv via:

sudo apt-get install opencv-dev

and libtiff via:

sudo apt-get install libtiff4-dev
like image 174
Kev1n91 Avatar answered Oct 24 '22 03:10

Kev1n91


Old question but still without an answer so here it goes (I came across the same error today):

  1. That is not why the linker fails. If it was able to find libtiff.so.5 it would have linked just fine.

  2. @ vs @@ is just a way to track difference versions of the function. More details here https://sourceware.org/binutils/docs/ld/VERSION.html

  3. LIBTIFF_4.0 means it is that specific version of TIFFOpen that is required when dynamically loading the symbol.

  4. That is probably a good way to fix the issue. It's likely that without the libtiff-dev package the libtiff.so symbolic linked file doesn't exit in /usr/lib/x86_64-linux-gnu/ so the linker will not be able to find the library (it knows nothing about libtiff.so.5 unless you tell it explicitly).

  5. a. You may be able to test 4. by invoking the linker command line yourself from the command line. If you compiled caffe with cmake you'll find the linker command under tools/CMakeFiles/caffe.bin.dir/link.txt. Just add /usr/lib/x86_64-linux-gnu/libtiff.so.5 to the command line and it should work.

    b. Alternatively manually create the symbolic link /usr/lib/x86_64-linux-gnu/libtiff.so

    c. install the dev package, which should do that for you. Also make sure that cmake knows about /usr/lib/x86_64-linux-gnu/ by specify extra library path

    d. check that there are no other libtiff.so library lurking in your system if previous steps don't work (e.g. anconda type thing)

Hope it helps.

like image 28
PoorBear Avatar answered Oct 24 '22 03:10

PoorBear


Install libtiff4-dev:

sudo apt-get install libtiff4-dev

like image 2
simurg Avatar answered Oct 24 '22 04:10

simurg


This is what worked for me: Go to Tiff website, and follow the instructions to download Tiff and build it, and install it. Then in your make file add this:

-L/[path to libtiff.so] -ltiff

If you want to know the path to the libtiff.so try this:

sudo find /usr/ -name libtiff.so
like image 1
Samer Avatar answered Oct 24 '22 05:10

Samer