简体   繁体   中英

CMake / error when linking libfreeimage / libtiff

I'm quite new to CMake, now I'm trying to compile the COLMAP software from https://colmap.github.io/ with it. It compiles the modules but when it comes to linking it fails with a number of errors like

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libfreeimage.so: undefined reference to `TIFFReadEncodedStrip@LIBTIFF_4.0'

I have libfreeimage and libtiff installed by the apt packages (libfreeimage-dev / libtiff4-dev). I also added libtiff explicitly to the dependencies in the CMakeLists-Files with the following

find_package(TIFF REQUIRED)

and

set(COLMAP_LIBRARIES
...
${FREEIMAGE_LIBRARIES}
${TIFF_LIBRARIES}

Do I have to set the libraries as having dynamic linkage somewhere in the CMake-File explicitly? Or what else could be the problem?

It looks like libfreeimage.so is trying to use the tiff library, example to include tiff in your project:

find_package( TIFF REQUIRED )
if ( TIFF_FOUND )
    include_directories( ${TIFF_INCLUDE_DIRS} )
    target_link_libraries( yourprojectname ${TIFF_LIBRARIES} )
endif( TIFF_FOUND )

If you have anaconda installed, please remove it from the path (in your ~/.zshrc / ~/.bashrc), then restart your shell.

sudo apt-get remove libtiff5-dev
sudo apt-get install libtiff5-dev

Then, try making the project again.

Disclaimer: Works on my machine:)

My configuration: Kubuntu 16.04 x64

I found a way to solve it. I hope it worked for u.

These problems are caused by the inability to find the appropriate library file.

Install the required package if it has not already been installed.If you have the required files in place, but the path is not correct, you can follow the following steps to resolve.

  1. ldd /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libfreeimage.so

Find the dependency files, it will output

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

Once the dependent file is found, the next step is the path to the library file to be used to replace the other location of the file.

2. locate libtiff.so

It will output

    ...
/home/username/anaconda3/lib/libtiff.so.5
/root/anaconda3/lib/libtiff.so.5    /var/lib/docker/aufs/diff/0faa9badda6fc687ec25d69baecdf401799f90cde729b0bf9fb2ed24dff76e4e/usr/lib/x86_64-linux-gnu/libtiff.so.5
...

You can see the path you want to replace.Sometimes there are more than one available item in the system, and if you are not sure which one to use, you can try it until you find the correct file.

To create a soft link, the source file is in front of the ln command, followed by the dependent location. For example,

ln -sf /var/lib/docker/aufs/diff/07382a150bf28b01a386095ec78a8d2e92fbf670393b3bd16b6f8fbc2d159ae1/usr/lib/x86_64-linux-gnu/libtiff.so.5 /usr/lib/x86_64-linux-gnu/libtiff.so.5 

Finally recompile, generally can be resolved. Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM