2
votes

What should appear in Makefile.am, configure.ac and the source to link a library to a program with Autotools?

My (currently trivial) project configures, builds and runs OK, but I want to tidy it up.

I currently have configure.ac:

dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(foo, 1.0)

AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()

AC_PROG_CC

AC_CONFIG_FILES(Makefile src/Makefile)
AC_OUTPUT

PKG_CHECK_MODULES([DEPS], [apr-1 >= 1.4.2])

Makefile.am (in src/):

bin_PROGRAMS=a.out
a_out_SOURCES=foo.c
a_out_LDADD = /usr/lib/libapr-1.so

and foo.c:

...
#include <apr-1.0/apr_general.h>
#include <apr-1.0/apr_pools.h>
...

I want to get rid of the hard-coded path to /usr/lib/libapr-1.so in Makefile.am and the relative #include paths in foo.c. I'm making a big assumption that PKG_CHECK_MODULES can find and tell me the locations of the files associated with libapr.

How should I modify these files to make this work?

Thanks,

Chris.

1

1 Answers

2
votes

Check out this tutorial.

The interesting part is if you define your pkg check like this:

PKG_CHECK_MODULES([APR], [apr-1 >= 1.4.2])

you can then use it in Makefile.am:

project_name_LDADD = $(APR_LIBS)