From a2520da19591599538f8dc26b3bd6bf7a2619300 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Sun, 10 Jan 2016 12:39:09 -0800 Subject: [PATCH] Fix static compilation (libc should be dynamically linked) --- Makefile.static-build | 2 +- configure.ac | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile.static-build b/Makefile.static-build index cb16c961..809ac9db 100644 --- a/Makefile.static-build +++ b/Makefile.static-build @@ -11,7 +11,7 @@ TMATE_CONFIGURE=PKG_CONFIG_PATH=./ext/lib/pkgconfig all: tmate dependencies: - apt-get install build-essentials cmake libssl-dev autoconf automake pkg-config libtool libevent-dev libncurses-dev zlib1g-dev + apt-get install build-essential cmake libssl-dev autoconf automake pkg-config libtool libevent-dev libncurses-dev zlib1g-dev downloads/$(notdir $(LIBSSH_URL)): mkdir -p downloads diff --git a/configure.ac b/configure.ac index 6c1c5b77..663a51c5 100644 --- a/configure.ac +++ b/configure.ac @@ -47,13 +47,12 @@ AC_ARG_ENABLE( found_static=$enable_static ) if test "x$found_static" = xyes; then - LDFLAGS="$LDFLAGS -static" PKG_CONFIG="pkg-config --static" CFLAGS="$CFLAGS -flto" LDFLAGS="$LDFLAGS -flto" - PKG_CHECK_MODULES([ZLIB], [zlib], [ + PKG_CHECK_MODULES([ZLIB], [zlib], [ CPPFLAGS="$ZLIB_CFLAGS $CPPFLAGS" LIBS="$ZLIB_LIBS $LIBS" ]) @@ -62,7 +61,6 @@ if test "x$found_static" = xyes; then CPPFLAGS="$LIBCRYPTO_CFLAGS $CPPFLAGS" LIBS="$LIBCRYPTO_LIBS $LIBS" ]) - AC_CHECK_LIB(dl, dlopen) fi # Is this gcc? @@ -451,6 +449,11 @@ if test "x$found_getopt" != xno; then fi AM_CONDITIONAL(NO_GETOPT, [test "x$found_getopt" = xno]) +if test "x$found_static" = xyes; then + # libc and libdl should be dynamically linked. + LIBS="-Wl,-Bstatic ${LIBS/-ldl/} -Wl,-Bdynamic -ldl" +fi + # Check for BSD-style integer types. AC_MSG_CHECKING(for BSD-style unsigned types) AC_COMPILE_IFELSE([AC_LANG_SOURCE(