Correcting the GCC command line ordering using Automake

后端 未结 2 865
情深已故
情深已故 2021-02-14 09:55

I have an autotools project that compiles just fine on the Mac, but under Linux (Ubuntu 12.04.1 LTS) the command lines passed to gcc have the libraries out of order

相关标签:
2条回答
  • 2021-02-14 10:36

    I solved a similar problem. The ./configure script in question was unable to complete a check for presence of a function due to a missing symbol. If I added the correct library to $LDFLAGS or such like, it was added before the .c file and the library was ignored.

    The names of functions to check are first added to ac_func_list and then there is a loop in the body of the ./configure that for each of them calls ac_fn_c_check_func () and that in turns calls ac_fn_c_try_link ()

    the checking function ac_fn_c_try_link () uses a command of this pattern:

    ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS \
             $LDFLAGS conftest.$ac_ext $LIBS >&5'
    

    $LDADD is completely ignored here. Therefore the only solution here is to add the -l flags to variable $LIBS.

    0 讨论(0)
  • 2021-02-14 10:56

    The solution turned out to be the difference between LDFLAGS and LDADD. In short LDFLAGS is added before the object files on the command line and LDADD is added afterwards. Thus, changing Makefile.am to the following solved the problem:

    CFLAGS=-Wall
    bin_PROGRAMS=test
    test_CFLAGS=$(GLIB_CFLAGS)
    test_LDADD=$(GLIB_LIBS)
    test_SOURCES=test.c
    

    It only took tracking down a GCC developer at work to solve. Also, this example I provided is rather poor because test has a defined meaning in some contexts of autotools.

    0 讨论(0)
提交回复
热议问题