1

I have a problem: I need to change the variable link_all_deplibs to 'no' in my libtool script. However my attempts to use _LT_AC_TAGVAR failed. Of course I can hack the libtool script after I run configure, but... It would be nice if I could do it in the way intended by autotools authors. Here is a sample configure.ac I used to test the feature:

AC_PREREQ(2.61)
AC_INIT([TEST_PROJ],[3.6],[a.a.godin@gmail.com])
dnl end versions

dnl project general settings
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_MACRO_DIR([m4])

AC_CANONICAL_TARGET
AC_CANONICAL_HOST
AC_CANONICAL_BUILD

AC_PROG_CC_C99
AC_PROG_CXX

AM_INIT_AUTOMAKE(TEST_PROJ, 3.6, foreign)
AC_PROG_LIBTOOL
_LT_AC_TAGVAR(link_all_deplibs,CXX)=no
_LT_AC_TAGVAR(link_all_deplibs,)=no
LT_INIT
AC_CONFIG_FILES(Makefile)
AC_OUTPUT

Your help is much appreciated. Thanks in advance. P.S.Do not merge it with --as-needed question. I've explained why this is a different question in a comment

Alexey Godin
  • 307
  • 1
  • 6
  • what problem are you trying to solve? with autotools (including libtool) it's **much** better to go with the flow rather than to enforce your ideas on how things ought to be done onto the system. (it's not always easy to stick to that paradigm; but not doing so usually results in burning a a lot of energy for little effect). – umläute Mar 20 '19 at 08:25
  • Let us say I really know what I am doing. And I need exactly the behavior that is governed by this option. I would kindly ask to provide answers not the best wishes how to write the project. The thing I want to find is how to do it .'autotools way' as surely an sed script applied post-configure will solve the problem for me. P.S.: For the curious: this option will make transition for the future versions more smooth because the executables won't include parasite links to the libraries they do not actually use. – Alexey Godin Mar 20 '19 at 15:33
  • Possible duplicate of [How do I link a shared library with --as-needed with automake?](https://stackoverflow.com/questions/6852414/how-do-i-link-a-shared-library-with-as-needed-with-automake) – umläute Mar 21 '19 at 10:33
  • No it is not. We a talking about the specific behavior of libtool: Suppose you have an executable test (like in my example) which you want to link with a shared library represented by libtest2.la. The libtest2.la in turn is linked to a shared library represented by libtest1.la. If link_all_deplibs is set to anything but no, both shared libraries will be linked to the executable. If link_all_deplibs is set to no, only libtest2.so will be linked.. – Alexey Godin Mar 21 '19 at 13:37
  • And this is what I need because I do not need the executable to be linked directly to the libraries I do not use. Note that this difference arises only when you build an executable in the same project as your libraries. – Alexey Godin Mar 21 '19 at 13:42
  • if you want a duplicate of this one see https://stackoverflow.com/questions/45282061/how-when-where-to-set-script-variables-of-libtool-e-g-hardcode-minus-l?rq=1 with no good answer either. – Alexey Godin Mar 21 '19 at 13:49
  • Try `_LT_TAGVAR` instead of `_LT_AC_TAGVAR` – Yann Droneaud Mar 21 '19 at 16:52
  • Already, autoconf does not recognize this macro. Besides _LT_AC_TAGVAR(variable,suffix) is expanded to variable_suffix if suffix is not empty and to variable if it is. So nothing magical in it. – Alexey Godin Mar 22 '19 at 13:55

1 Answers1

0

I had the opposite problem where I was cross compiling and my debian based distribution was setting the aforementioned variable link_all_deplibs to 'no' and it was causing link errors. I found here that others had solved this with the following addition to the configure.ac file.

AC_PROG_GREP
AC_ARG_ENABLE(libtool-linkdep-fixup,
    AS_HELP_STRING([--disable-libtool-linkdep-fixup],
                   [disable the libtool fixup for linking all dependent libraries (link_all_deplibs)]),
    libtool_fixup=$enableval,
    libtool_fixup=yes)

AS_IF([test "x$libtool_fixup" = "xyes"],
    [
    libtool_m4="$srcdir/config/libtool.m4"
    libtool_flag_pattern=".*link_all_deplibs\s*,\s*\$1\s*)"
    AC_MSG_CHECKING([for occurence(s) of link_all_deplibs = no in $libtool_m4])
    libtool_flag_pattern_count=$(grep -c "$libtool_flag_pattern\s*=\s*no" $libtool_m4)
    AS_IF([test $libtool_flag_pattern_count -ne 0],
        [
        AC_MSG_RESULT([$libtool_flag_pattern_count])
        AC_MSG_WARN([the detected libtool will not link all dependencies, forcing link_all_deplibs = unknown])
        sed -i "s/\($libtool_flag_pattern\)\s*=\s*no/\1=unknown/g" $libtool_m4
        ],
        [
        AC_MSG_RESULT([none])
        ])
    ])

This changes the value of variable link_all_deplibs from 'no' to 'unknown' but could easily be tweaked to perform the change you desire instead.

yoyoma2
  • 101
  • 1