## Fixing bmake to compile dynamic libraries on Linux

Posted by Diego Assencio on 2015.01.19 under Linux (General)

If you are using bmake to compile a software project which uses BSD make and get an error like the one below:

cc: error: <libname>.so.1: No such file or directory
cc: error: unrecognized command line option ‘-soname’
*** Error code 1


The fix is simple. Unfortunately, the bmake package on Ubuntu/Debian (and possibly also on other Linux distributions) has a bug on one of its BSD makefiles, but all you need to do it to open /usr/share/mk/bsd.lib.mk:

nano /usr/share/mk/bsd.lib.mk


and replace this line:

SHLIB_SHFLAGS=          -soname lib${LIB}.so.${SHLIB_SOVERSION}


with this:

SHLIB_SHFLAGS=          -Wl,-soname=lib${LIB}.so.${SHLIB_SOVERSION}


The -Wl flag passes options to the linker. In the case above, -Wl,-soname is used to set the logical name of the shared object <libname>.so.1 (i.e., a dynamic library) which is created during the compilation of the project. These logical names are used by the dynamic linker to determine the filenames of the dynamic libraries which a given executable needs to run: the executable usually only specifies the logical names of the dynamic libraries and the dynamic linker must then figure out where these libraries are actually located in the system. Readers who are more interested in this topic can find lots of detailed information in this post.