-lfoo vs /usr/local/lib/libfoo.so

Gary Aitken freebsd at dreamchaser.org
Fri Dec 7 18:43:47 UTC 2018

In trying to build a dev version of a port, the cmake script includes
many libraries explicitly, and one (-lhdf5-18) using -l:

/usr/bin/c++ -fPIC -Wall -Wextra -Wno-write-strings -O2 -pipe
  -I/usr/local/include/hdf5-18 -fstack-protector -isystem /usr/local/include
  -fno-strict-aliasing  -isystem /usr/local/include -std=c++11
  -Wno-undefined-var-template -D_OCC64 -O2 -pipe -I/usr/local/include/hdf5-18
  -fstack-protector -isystem /usr/local/include -fno-strict-aliasing  -isystem
  /usr/local/include -Wl,--no-undefined -shared
  -Wl,-soname,libFreeCADBase.so -o ../../lib/libFreeCADBase.so
... a bunch of .o files ...
  -Wl,-rpath,/usr/local/lib:/usr/local/lib/qt4: -lhdf5-18
... <more .so files> ...
  -lpthread -lz /usr/local/lib/qt4/libQtCore.so

The above command fails with
   "/usr/bin/ld: cannot find -lhdf5-18"
exists and the rpath flag indicates /usr/local/lib

If I replace -lhdf5-18 with /usr/local/lib/libhdf5-18.so it works.
Curiously (to me) -lpthread and -lz are apparently working correctly,
or at least aren't being mis-interpreted.

I've tried tweaking the command to use -Wl,-lhdf5-18 but that fails also.
Can anyone explain to me what's going on?


More information about the freebsd-questions mailing list