Error while loading shared libraries, cannot open shared object file: No such file or directory (hiredis)
Solution 1
The problem was the libhiredis wasn't in the ldconfig path. While the build process was correct and it copied everything to the correct directory ldconfig did not know about its location.
You can use ldconfig -p
to see all library ldconfig currently know about.
You can add the path to ldconfig with
sudo echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf
&
sudo ldconfig
Solution 2
Since an a.out file was produced, that means it compiled and linked properly. When you run a.out, the libhiredis.so.0.13: cannot open shared object file: No such file or directory
error message means that the library is not in your library search path.
Double check that libhiredis.so.0.13 is installed to a standard lib directory (/lib64, /usr/lib64, /usr/local/lib64), or add the directory containing it to LD_LIBRARY_PATH
.
Related videos on Youtube
T. Thomas
Updated on July 09, 2022Comments
-
T. Thomas almost 2 years
I'm in the alpha stages of writing a C program which uses redis on the back end.
I've tried building/installing hiredis (make && sudo make install) and running the test (which pass mostly) but when trying to build the example.c program i get an error that hiredis.h couldn't be found.
Building on the command line with: gcc -v example.c -l hiredis -I /usr/local/include/hiredis/
Things I've tried:
- pkg-info hiredis returns 0
- uninstall/reinstall via (make && ./hiredis-test && sudo make) and (make clean)
- building example.c in the same directory as hiredis.c and hiredis.h (still No Such file or directory)
- gcc -v example.c -l hiredis -I /usr/local/include/hiredis/ (And other variations of this)
All with no luck.
I'm guessing I'm not linking the programs correctly for gcc but the documentation doesn't have any build examples.
What am I doing wrong that wont let me build this code (or any code) using hiredis?
the exact output is...
Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) COLLECT_GCC_OPTIONS='-v' '-I' '/usr/local/include/hiredis/' '-mtune=generic' /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1 -quiet -v -I /usr/local/include/hiredis/ example.c -quiet -dumpbase example.c -mtune=generic -auxbase example -version -o /tmp/ccWP2etT.s ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include/hiredis/ /usr/local/include /usr/lib/gcc/x86_64-redhat-linux/4.4.7/include /usr/include End of search list. GNU C (GCC) version 4.4.7 20120313 (Red Hat 4.4.7-16) (x86_64-redhat-linux) compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-16), GMP version 4.3.1, MPFR version 2.4.1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 8fd7a5b48f606b047c876a297c82f28e COLLECT_GCC_OPTIONS='-v' '-I' '/usr/local/include/hiredis/' '-mtune=generic' as -V -Qy -o /tmp/ccnscL6h.o /tmp/ccWP2etT.s GNU assembler version 2.20.51.0.2 (x86_64-redhat-linux) using BFD version version 2.20.51.0.2-5.43.el6 20100205 COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-I' '/usr/local/include/hiredis/' '-mtune=generic' /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/collect2 --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../.. /tmp/ccnscL6h.o -lhiredis -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crtn.o
Which produces an a.out. When trying to run that program. I get the following error.
./a.out: error while loading shared libraries: libhiredis.so.0.13: cannot open shared object file: No such file or directory
-
David C. Rankin almost 6 yearsIt sounds like you need to add the Include Search Path to
hiredis.h
to your compile string, e.g.-I /full/path/to/hiredis.h
. (where ishiredis.h
currently installed?) If you compile your test withgcc -v ...
it will show the current include search paths after#include "..." search starts here:
and#include <...> search starts here: