FLIF-hub / FLIF

Free Lossless Image Format
Other
3.72k stars 229 forks source link

Executable from 'make flif' fails: libflif.so.0 not found #432

Closed BenWiederhake closed 7 years ago

BenWiederhake commented 7 years ago

I want only the flif executable. I followed the build instructions in the README.md, which boiled down to typing

~/FLIF$ cd src
~/FLIF/src$ make flif
g++ -std=gnu++11 -I/usr/include/libpng16 -DLODEPNG_NO_COMPILE_PNG \
-DLODEPNG_NO_COMPILE_DISK -DNDEBUG -O2 -flto -g0 -Wall -shared -fPIC \
maniac/chance.cpp maniac/symbol.cpp image/crc32k.cpp image/image.cpp image/image-png.cpp \
image/image-pnm.cpp image/image-pam.cpp image/image-rggb.cpp image/image-metadata.cpp \
image/color_range.cpp transform/factory.cpp common.cpp flif-enc.cpp flif-dec.cpp io.cpp \
../extern/lodepng.cpp library/flif-interface.cpp -lpng16 -Wl,-soname,libflif.so.0 -o libflif.so.0
ln -sf libflif.so.0 libflif.so
g++ -std=gnu++11 -I/usr/include/libpng16 -DLODEPNG_NO_COMPILE_PNG \
-DLODEPNG_NO_COMPILE_DISK -DNDEBUG -O2 -ftree-vectorize -flto -g0 -Wall flif.cpp \
-lpng16 -L. -lflif -o flif
~/FLIF/src$ ./flif 
./flif: error while loading shared libraries: libflif.so.0: cannot open shared object file: No such file or directory
~/FLIF/src$ ls
CMakeLists.txt         config.h       flif.cpp      flif-enc.hpp          io.hpp        Makefile
common.cpp             fileio.hpp     flif-dec.cpp  flif-pixbuf-loader.c  libflif.so    maniac
common.hpp             flif           flif-dec.hpp  image                 libflif.so.0  transform
compiler-specific.hpp  flif_config.h  flif-enc.cpp  io.cpp                library       viewflif.c
~/FLIF/src$ file libflif.so.0 
libflif.so.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, \
BuildID[sha1]=2f2c41fbf5cd98ec3dbfb2dfd5b0acb2f796b12a, not stripped
~/FLIF/src$ LD_PRELOAD=libflif.so.0 ./flif
ERROR: ld.so: object 'libflif.so.0' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
./flif: error while loading shared libraries: libflif.so.0: cannot open shared object file: No such file or directory

So in short:

Could it be that gcc somehow ignores the -shared option? For reference, I'm running this:

$ g++ --version
g++ (Debian 6.3.0-16) 6.3.0 20170425
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

What else could I try?

hrj commented 7 years ago

Dynamically linked libraries need to be in the linker's "path". So, you need to run it like this:

LD_LIBRARY_PATH=./ ./flif

Or, copy the flif library to one of the standard paths, such as /usr/lib/.

hrj commented 7 years ago

Oh, I had missed your LD_PRELOAD option. It does work for me, on Ubuntu 16.04.

Does LD_LIBRARY_PATH work for you?

BenWiederhake commented 7 years ago

It does, thanks! Would it make sense to open a PR that touches up the text to mention LD_LIBRARY_PATH?

hrj commented 7 years ago

@BenWiederhake Yeah :+1:

Note that the linking to a dynamic library is a new thing. Previously we were statically linking the flif executable.

BenWiederhake commented 7 years ago

Great :+1: