3

I installed zeromq 3.2.5 from source

$ wget http://download.zeromq.org/zeromq-3.2.5.tar.gz
$ tar xf zeromq-3.2.5.tar.gz
$ cd zeromq-3.2.5
$ ./configure && make -j4
$ sudo make install

This installs libzmq.so.3 into /usr/local/lib:

$ sudo updatedb
$ locate libzmq.so.3
/usr/local/lib/libzmq.so.3
/usr/local/lib/libzmq.so.3.0.0

I've confirmed that /usr/local/lib is in the ld search path:

$ grep /usr/local/lib /etc/ld.so.conf.d/*
/etc/ld.so.conf.d/libc.conf:/usr/local/lib

I've confirmed that ld can find the library:

$ ldconfig -v 2>/dev/null | egrep -e zmq\|^/
...
/usr/local/lib:
  libzmq.so.3 -> libzmq.so.3.0.0
...

However, if I run ldd on my app, it cannot find libzmq.so.3

$ ldd test_app
  ...
  libzmq.so.3 => not found
  ...

If I set LD_LIBRARY_PATH then it works

$ export LD_LIBRARY_PATH=/usr/local/lib
$ ldd test_app
  ...
  libzmq.so.3 => /usr/local/lib/libzmq.so.3 (0x00007f22418d9000)
  ...

Question:

  • Why can't ld find libzmq.so.3 without LD_LIBRARY_PATH when it's in a standard path?
  • How can I fix this without having to set LD_LIBRARY_PATH?

Notes:

The RPATH is set on the binary, in case that's important:

$ readelf -a test_app | grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [/home/steve/src/.../bin/gcc-4.9.3/debug]

I'm running Ubuntu 14.04 in case that's of any use

  • Can you get -rpath=/usr/local/lib passed to the linker when compiling the test app? Via gcc this may require -Wl,-rpath=... in addition to however that home directory path is being added. – thrig Jul 21 '16 at 18:41
  • @thrig yes I could, but that doesn't seem right - more like treating the symptoms not the cause? I don't understand why if /usr/local/lib is in ld.conf, why it can't find it? – Steve Lorimer Jul 21 '16 at 18:54
  • Have you run ldconfig without flags as root user to update the cache? This is sometimes needed after a new library has been added. – Stephen Harris Jul 21 '16 at 18:56
  • @StephenHarris ah, yes, that worked! How come ldconfig -v could find it? If you want to put that in an answer I'll gladly accept it. Thanks! – Steve Lorimer Jul 21 '16 at 18:58
  • You ran ldconfig -v as a non-root user if your $ prompt is anything to go by. This just made it scan the directories but couldn't update the cache for the runtime linker. – Stephen Harris Jul 21 '16 at 19:01
2

When you add new libraries to the system directories you may need to refresh the linker cache with

ldconfig

This needs to be run as root.

Without this command the runtime linker will have a stale idea of what libraries are available.

You similarly need to do this if you decide to add new directories to the system linker path.

Setting LD_LIBRARY_PATH caused the runtime linker to manually look in that directory, outside of the cache.

| improve this answer | |
  • 4
    Warning: running ldconfig without options is Linux-specific. If you'd do that on OpenBSD you'd actually clear the shared library cache. – Satō Katsura Jul 21 '16 at 19:13
  • Good warning; in this case we know it's Ubuntu but definitely worth highlighting the differences! Thanks. – Stephen Harris Jul 21 '16 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.