I'm just getting started with autotools, and have followed A. Duret-Lutz's tutorial closely to get a working C hello world that uses GNU gettext.
The AM_CFLAGS and AM_LDFLAGS are set appropriately in the Makefile.am, and the code compiles and runs successfully.
The issue is that autoconf is not searching in the directories that AM_CFLAGS and AM_LDFLAGS is telling the compiler to search, and as a result not defining the HAVE_GETTEXT_H, HAVE_LIBINTL, etc. macros in the config.h.
How can I get the configure.ac to supplement the library and include directories it searches when using AC_CHECK_LIB and AC_CHECK_HEADERS?
I think I misread the original question but since nothing in my other answer is incorrect per se I'll add another answer.
In order to use custom paths in AC_CHECK_HEADER
and AC_CHECK_LIBS
one has to (temporarily) set CFLAGS
and LDFLAGS
accordingly:
CFLAGS_backup="${CFLAGS}"
LDFLAGS_backup="${LDFLAGS}"
CFLAGS="-I/path/to/an/additional/include/ ${CFLAGS}"
LDFLAGS="-L/path/to/the/lib/ ${LDFLAGS}"
AC_CHECK_HEADER(...)
AC_CHECK_LIB(...)
## reset CFLAGS and LDFLAGS
CFLAGS="${CFLAGS_backup}"
LDFLAGS="${LDFLAGS_backup}"
Within AC_CHECK_*
you'd typically set GETTEXT_CFLAGS
or LIBINTL_LIBS
as variables and export them for use in automake per AC_SUBST([GETTEXT_CFLAGS])
and AC_SUBST([LIBINTL_LIBS])
respectively.
Unfortunately, you cannot access AM_CFLAGS
or AM_LDFLAGS
in configure.ac.
Now in Makefile.am
you can use
AM_CFLAGS = $(GETTEXT_CFLAGS) <other stuff>
AM_LDFLAGS = $(GETTEXT_LIBS) <other stuff>
For convenience, typically, you'd expose a parameter to the user as well, either via AC_ARG_WITH
or AC_ARG_VAR
, so they can use --with-gettext
or LIBINTL_LIBS=...
along with the configure command.
Seeing as autoconf is really only m4 you could wrap the above in a macro yourself. And seeing as we talk about gettext here, there is already such a thing: AM_GNU_GETTEXT
, an m4 macro that you could use in your configure.ac after you called gettextize
.
Instead of AC_CHECK_HEADER
, use AC_CHECK_HEADERS
, that defines tokens of the form HAVE_<HEADER>_H
. The singular form expects you to define things yourself using the ACTION-IF-FOUND
(2nd argument).
For AC_CHECK_LIB
there is no such comfort, you must use the ACTION-IF-FOUND
(3rd argument) and AC_DEFINE
whatever is needed.
Additionally there will be shell variables ac_cv_header_<HEADER>_h
and ac_cv_lib_<LIBRARY>_<FUNCTION>
set.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.