3

I am working on an open-source software package that I would like to distribute as a binary. It requires a shared library that is built using:

aclocal
automake --add-missing
autoconf
./configure
make install

Which gives these libraries:

libMUSCLE-3.7.a  
libMUSCLE-3.7.la  
libMUSCLE-3.7.so  
libMUSCLE-3.7.so.1  
libMUSCLE-3.7.so.1.0.0  
pkgconfig

and the package is then built using

aclocal
automake --add-missing
autoconf
make LDADD=-lMUSCLE-3.7
make install

However, after building the final executable foo, if I move foo to another system, I get the complaint that libMUSCLE-3.7.so.1 can't be found. I've tried moving foo along with the libMUSCLE libraries so that the relative structure is saved, but it seems like somewhere in the foo executable, there is a hardcoded full path to the shared library. How can I compile foo so that it is standalone. Alternatively, can I compile foo so that it uses a relative path to find the shared library?

Below are the configure.ac files for autoconf:

libMUSCLE configure.ac:

dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.59])
AC_INIT(libMUSCLE/muscle.h)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR([m4])

dnl -----------------------------------------------
dnl Package name and version number (user defined)
dnl -----------------------------------------------

GENERIC_LIBRARY_NAME=libMUSCLE

#release versioning
GENERIC_MAJOR_VERSION=1
GENERIC_MINOR_VERSION=0
GENERIC_MICRO_VERSION=0

#API version (often = GENERIC_MAJOR_VERSION.GENERIC_MINOR_VERSION)
GENERIC_API_VERSION=3.7
AC_SUBST(GENERIC_API_VERSION)

#shared library versioning
GENERIC_LIBRARY_VERSION=1:0:0
#                       | | |
#                +------+ | +---+
#                |        |     |
#             current:revision:age
#                |        |     |
#                |        |     +- increment if interfaces have been added
#                |        |        set to zero if interfaces have been removed
#                                  or changed
#                |        +- increment if source code has changed
#                |           set to zero if current is incremented
#                +- increment if interfaces have been added, removed or changed

dnl --------------------------------
dnl Package name and version number
dnl --------------------------------

AC_SUBST(GENERIC_LIBRARY_VERSION)

PACKAGE=$GENERIC_LIBRARY_NAME
AC_SUBST(GENERIC_LIBRARY_NAME)

GENERIC_VERSION=$GENERIC_MAJOR_VERSION.$GENERIC_MINOR_VERSION.$GENERIC_MICRO_VERSION
GENERIC_RELEASE=$GENERIC_MAJOR_VERSION.$GENERIC_MINOR_VERSION
AC_SUBST(GENERIC_RELEASE)
AC_SUBST(GENERIC_VERSION)

VERSION=$GENERIC_VERSION

AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)

dnl Override default O2
CFLAGS=${CFLAGS-""}
CXXFLAGS=${CXXFLAGS-""}

AC_PREFIX_DEFAULT(/usr/local)

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_LN_S 
AM_PROG_LIBTOOL

dnl Check what compiler we're using
AM_CONDITIONAL(ICC, test x$CC = xicc )

dnl Checks for header files.
AC_HEADER_STDC

dnl Allow debugging compilation
AC_ARG_ENABLE(debug,
[  --enable-debug    Turn on debugging],
[case "${enableval}" in
  yes) debug=true ;;
  no)  debug=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
esac],[debug=false])
AM_CONDITIONAL(DEBUG, test x$debug = xtrue)

dnl Mac OS X won't allow static compilation...
STATIC_FLAG=""
if ( test "x$target_vendor" = "xapple") then
        STATIC_FLAG=""
fi
AC_SUBST(STATIC_FLAG)

dnl Check for OpenMP
#AX_OPENMP()
AC_SUBST(OPENMP_CFLAGS)
dnl OpenMP checker only defines for C when compiling both C and C++
OPENMP_CXXFLAGS=$OPENMP_CFLAGS
AC_SUBST(OPENMP_CXXFLAGS)

dnl Make doxygen docs
#DX_INIT_DOXYGEN( "libMUSCLE", "projects/libmuscle.doxygen", "doc" )

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
dnl AC_C_BIGENDIAN
AC_HEADER_TIME

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL

dnl SAVE_LIBRARY_VERSION
AC_SUBST(LIBTOOL_VERSION_INFO)

AC_OUTPUT(Makefile libMUSCLE/Makefile libMUSCLE-3.7.pc )

foo configure.ac

AC_INIT(parsnp,1.0)
AM_INIT_AUTOMAKE(parsnp,1.0)
AC_PROG_CC(gcc)

AC_ARG_WITH(libmuscle, [  --with-libmuscle=<path/to/libmuscle>     libMUSCLE install dir (default: `pwd`/muscle)])

if test "$with_libmuscle" == ""
then
    with_libmuscle=`pwd`/muscle
fi

AC_LANG(C++)

CPPFLAGS="-I$with_libmuscle"
AC_CHECK_HEADER(libMUSCLE/muscle.h, [result=1], [result=0])

if test $result == 0
then
    AC_MSG_ERROR([libMUSCLE  headers not found.])
fi

AC_SUBST(libmuscle, $with_libmuscle)
AC_OUTPUT(Makefile src/Makefile)
Throckmorton
  • 564
  • 4
  • 17
  • 1
    your configure scripts probably have static options – Alan Birtles May 25 '20 at 19:58
  • 1
    It is not possible to conclusively determine the solution without inspecting the exact build commands. But in general: inspect which `-rpath` option gets passed to the linker when building the shared library, and remove one if it's there. Other options include linking with `--enable-new-dtags`, which will allow shared library searches to prioritize `LD_LIBRARY_PATH` ahead of the runtime search path that's embedded in the shared library. – Sam Varshavchik May 25 '20 at 20:02
  • 1
    Look into `rpath` (or link statically - if possible (technically as well as legally)). – Jesper Juhl May 25 '20 at 20:08
  • I'm very new to autoconf (and building in general), so I'll take any help I can get. I've pasted the `configure.ac` files above, hopefully that will help. – Throckmorton May 25 '20 at 22:56

0 Answers0