Chris Snow
Chris Snow

Reputation: 24596

AC_SEARCH_LIBS is not finding my library

I'm currently learning autotools and have been trying to work out how to use AC_SEARCH_LIBS so I have picked a function at random from the glib manual to include in my c project:

gint g_ascii_digit_value (gchar c);

Next I added a AC_SEARCH_LIBS macro to my configure.ac:

AC_INIT([myproject], [123], [[email protected]])
AC_SEARCH_LIBS([g_ascii_digit_value], [glib], [], [
  AC_MSG_ERROR([unable to find the g_ascii_digit_value() function])
])
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_OUTPUT([Makefile src/Makefile])

However, when I run autoreconf -i followed by ./configure, I get the error:

configure: error: unable to find the g_ascii_digit_value() function

I am using OS X and have checked that I have the glib library installed:

snowch:autoconf snowch$ brew install glib
Warning: glib-2.42.1 already installed

What I am doing wrong?

Upvotes: 0

Views: 1614

Answers (1)

Chris Snow
Chris Snow

Reputation: 24596

After a bit of searching, I found that I needed to use PKG_CHECK_MODULES as shown below:

AC_INIT([myproject], [123], [[email protected]])

PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.3.0])
AC_SUBST([GLIB_CFLAGS])
AC_SUBST([GLIB_LIBS])

AM_INIT_AUTOMAKE
AC_PROG_CC
AC_OUTPUT([Makefile src/Makefile])

Then the GLIB variables needed to be added to src/Makefile.am:

bin_PROGRAMS = helloworld

helloworld_SOURCES = main.c
helloworld_LDADD = @GLIB_LIBS@
helloworld_CFLAGS = @GLIB_CFLAGS@

Upvotes: 3

Related Questions