compilationlinkerautotoolsdynamic-linkingldflags

Is it possible to set the compiling and linking flags in Makefile.am instead of configure.ac?


Is it possibleto set such flags in Makefile.am instead? That will solve the problem I asked at https://stackoverflow.com/questions/22617744/how-to-disable-the-runtime-checking-of-dynamic-libraries-if-they-are-not-used.


Solution

  • If you are using Autoconf and Automake, then you should be able to pass in linker flags at compile time to make using the following:

    make LDFLAGS='-L/my/nonstandard/prefix/lib' target
    

    Additionally, you can do this for CC, CFLAGS, CPP, CPPFLAGS, and LIBS. For example:

    make CC=gcc-4.2 \
        LIBS='-lmylibrary -lhislib ../lib/libcustom.a' \
        LDFLAGS='-L/opt/vend/lib' \
        CPPFLAGS='-I../include' \
        CFLAGS='-Wall' \
        target
    

    If you want to make them permanent in the make file, add them the to automake variables:

    AM_LIBS     = -lmylibrary -lhislib ../lib/libcustom.a
    AM_LDFLAGS  = -L/opt/vend/lib
    AM_CPPFLAGS = -I../include
    AM_CFLAGS   = -Wall
    

    Using the above variables, will still allow you to add flags by passing them to make using the previous method.