Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library resolution with autoconf?

Tags:

autoconf

I'm building my first autoconf managed package.

However I can't find any simple examples anywhere of how to specify a required library, and find that library where it might be in various different places.

I've currently got:

AC_CHECK_LIB(['event'], ['event_init'])

but:

  1. It doesn't find the version installed in /opt/local/lib
  2. It doesn't complain if the library isn't actually found
  3. I need to set the include path to /opt/local/include too

any help, or links to decent tutorials much appreciated...

like image 464
Alnitak Avatar asked Feb 05 '09 19:02

Alnitak


People also ask

What is Autoconf used for?

GNU Autoconf is a tool for producing configure scripts for building, installing, and packaging software on computer systems where a Bourne shell is available. Autoconf is agnostic about the programming languages used, but it is often used for projects using C, C++, Fortran, Fortran 77, Erlang, or Objective-C.

How do I setup a script autoconf?

To create a configure script with Autoconf, you need to write an Autoconf input file configure.ac (or configure.in ) and run autoconf on it. If you write your own feature tests to supplement those that come with Autoconf, you might also write files called aclocal. m4 and acsite.


4 Answers

autoconf script cannot guess the "optional" library locations, which may vary from one platform to another. So you can say

CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib" ./configure 

For AC_CHECK_LIB() you need to specify the fail condition explicitly in "action-if-false" argument:

dnl This is simply print "no" and continue: AC_CHECK_LIB([m], [sqrt123]) dnl This will stop: AC_CHECK_LIB([m], [sqrt123], [], [AC_MSG_ERROR([sqrt123 was not found in libm])]) 

Output:

checking for sqrt123 in -lm... no checking for sqrt123 in -lm... no configure: error: sqrt123 was not found in libm 

AC_CHECK_LIB() does not fail by default on obvious reasons: one may check for several different libraries that provide similar functionality and choose one of them :)

Also have a look at this post for similar topic.

like image 106
dma_k Avatar answered Sep 20 '22 03:09

dma_k


You need to manually set CFLAGS, CXXFLAGS and LDFLAGS if you want gcc/g++ to look in non-standard locations.

So, before calling AC_CHECK_LIB(), do something like

CFLAGS="$CFLAGS -I/opt/local/include" CXXFLAGS="$CXXFLAGS -I/opt/local/include" LDFLAGS="$LDFLAGS -L/opt/local/lib" 

You don't need CXXFLAGS if you're only using gcc throughout your configure script.

like image 36
codelogic Avatar answered Sep 18 '22 03:09

codelogic


If the library ships a .pc file, consider using the PKG_CHECK_MODULES() macro which does the things you want. If it's your own library, just ship a .pc file into /usr/lib/pkgconfig, it'll make it much easier for other developers to depend/use it.

like image 39
Johan Dahlin Avatar answered Sep 20 '22 03:09

Johan Dahlin


I know this is an old thread now, but I guess this may help some people out. This is how I find some stuff.

hdff="no"
hdffprefix="ERROR"
AC_ARG_WITH(hdf,[  --with-hdf              Compile with hdf library, for output.],[hdffprefix=$withval hdff="yes"],[])
# if there is no value given, it appears tha hdffprefix is set to "yes"
if test $hdffprefix = "yes" -a $hdff = "yes"
then
    echo "HDF: Attempting to find HDF"
    hdffprefix="ERROR"

    # check if hdffprefix is set, if it is not, it sets it to "ERROR" and the 
    # 'if' comparison evaluates to true
    if [[ "$hdffprefix" == "ERROR" ]]
    then
        echo "HDF: hdffprefix not set, searching PATH"
        for i in `echo $PATH | tr ':' '\n'`
        do
            if [[ $i == *hdf* ]]
            then
                if [[ $i == *bin/* ]]
                then
                    hdffprefix=${i%bin/}
                    # if it doesn't exist, re-set to ERROR
                    if [[ ! -f ${hdffprefix}include/hdf.h ]]
                    then
                    hdffprefix="ERROR"
                    fi
                elif [[ $i == *bin* ]]
                then
                    hdffprefix=${i%bin}
                    # if it doesn't exist, re-set to ERROR
                    if [[ ! -f ${hdffprefix}include/hdf.h ]]
                    then
                    hdffprefix="ERROR"
                    fi
                fi
            fi
        done
        if [[ "$hdffprefix" == "ERROR" ]]
        then
            echo "HDF: hdffprefix not found in PATH, trying 'which'"
            WHICH_TEST_HDF=`which hdf2gif`
            if [[ WHICH_TEST_HDF != "" ]]
            then
                hdffprefix=${WHICH_TEST_HDF%bin/hdf2gif}
            else
                echo "HDF: Warning - hdf not found"
            fi
        fi
    fi
    if [[ "$hdffprefix" != "ERROR" ]]
    then
        hdff="yes"
        echo "HDF found: $hdffprefix"
    fi
fi
if test $hdff = 'yes'; then
        hdfincs=" -DUSE_HDF -I"${hdffprefix}"include"
        scriptotherlibsinc=${scriptotherlibsinc}" -L"${hdffprefix}"/lib"
        scriptotherlibs=${scriptotherlibs}" -lmfhdf -ldf -ljpeg -lz"
    AC_CHECK_HEADERS([${hdffprefix}/include/hdf.h],,[AC_MSG_ERROR([Cannot find hdf.h])])
    AC_CHECK_HEADERS([${hdffprefix}/include/mfhdf.h],,[AC_MSG_ERROR([Cannot find mfhdf.h])])
fi
like image 27
NAH Avatar answered Sep 19 '22 03:09

NAH