0

Command to build executable:
g++ -I../include/redis -L../lib/redis redis.cpp -o redis -lhiredis

Description:
I have libhiredis.so in ../lib/redis/. And in /usr/local/lib/hiredis13/, there are libhiredis.so and libhiredis.so.0.13, this libhiredis.so is a symbol link to libhiredis.so.0.13.Then I ldd redis, here is the result:

linux-vdso.so.1 => (0x00007ffd227f7000) libhiredis.so.0.13 => not found libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f7ebca0d000) libm.so.6 => /lib64/libm.so.6 (0x00007f7ebc70b000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f7ebc4f5000) libc.so.6 => /lib64/libc.so.6 (0x00007f7ebc132000) /lib64/ld-linux-x86-64.so.2 (0x00007f7ebcd23000) 

Gcc should link to libhiredis.so in ../lib/redis/, am I right?

4
  • libhiredis.so in ../lib/redis/ is not a symbol link. Commented Oct 25, 2016 at 7:32
  • @GundolfGundelfinger Thank you.I rename libhiredis.so to libhiredis.so.0.13 and make libhiredis.so a symbol link of libhiredis.so.0.13.Thant worked! :-) Commented Oct 25, 2016 at 7:44
  • DON'T RENAME -- create a symlink to the original. (or build with the proper name to begin with :) Commented Oct 25, 2016 at 7:58
  • @DavidC.Rankin The original is libhiredis.so which is not a symlink, so I rename it and create a symlink to it. Commented Oct 25, 2016 at 11:11

1 Answer 1

3

Probably your library has a SONAME (libhiredis.so.0.13) so the program records it instead of the name of the file. Then, in runtime, that SONAME is searched for in the usual directories.

Your library is in /usr/local/lib/hiredis13/, and that is not a usual directory. The solution is one of the following:

  • Add the /usr/local/lib/hiredis13 directory in /etc/ld.so.conf or /etc/ld.so.conf.d/* and re-run ldconfig.
  • Export the environment variable LD_LIBRARY_PATH=/usr/local/lib/hiredis13 when running the program.
  • Use the -rpath linker option.
Sign up to request clarification or add additional context in comments.

4 Comments

The -rpath method is a good choice as it will embed the library path in the executable making it immune from updates/changes that reset or alter ld.so.conf or LD_LIBRARY_PATH
@DavidC.Rankin Agreed, I prefer LD_LIBRARY_PATH to others.
@DavidC.Rankin: Personally, I prefer the LD_LIBRARY_PATH and a shell script that exports it and launches the binary.
Both have advantages and inconveniences.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.