tags:

views:

1394

answers:

5

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...

+2  A: 

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.

codelogic
I presume that first line should be CPPFLAGS, not CFLAGS?
Alnitak
I did mean CFLAGS in the first line, however as far as include headers go, CPPFLAGS should also do the trick.
codelogic
@codelogic I agree with Alnitak in the sense that it is advised to use CFLAGS/CXXFLAGS (depending on C/C++ compiler you intend to use) should only be used for compiler arguments (like "-g", "-O3"). Includes should go to CPPFLAGS (C Pre Processor).
dma_k
+2  A: 

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.

Johan Dahlin
A: 

*AC_CHECK_LIB* creates and compiles a simple temporary program that calls the function, passing the library in on the link line. If the program compiles successfully, *AC_CHECK_LIB* knows that the function exists in that library. If compilation fails, it knows that the function doesn't exist there, even though it might be somewhere else on the system.

Which means that it is a pretty dumb tool. You have to either provide the necessary flags to the environment (set them in the autoconf script before testing for the library based for example on *AC_ARG_WITH* or provide them externally before invoking configure script).

Personally I had enough of fun with autotools and moved to CMake.

Anonymous
A: 

Does this Documentation on AC_CHECK_LIB help at all?

leed25d
A: 

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.

dma_k