0

I am using FreeBSD and have installed iconv package form port collection.I wrote

AC_CHECK_HEADER([iconv.h], ,[AC_MSG_ERROR([can not find iconv.h])]) AC_CHECK_LIB([iconv], [iconv_open], ,[AC_MSG_ERROR([can not find iconv_open])])

in the configure.ac.But when I run ./configure, it gave me the following message

checking iconv.h usability... no

checking iconv.h presence... no

checking for iconv.h... no

configure: error: can not find iconv.h

I am sure there is iconv.h, libiconv.la, libiconv.so in the directory of /usr/local/include and /usr/local/lib.So how should I write the correct statement to check the header file and library.Thanks advance!!

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
MYMNeo
  • 818
  • 5
  • 9

3 Answers3

1

You should not modify your configure.ac in any way. The user is responsible for telling the tool chain where to look for libraries. For the user (which is who you are when you run configure), an easy thing to do is to set up a config.site so that the appropriate flags are set. For example, in your .bashrc: export CONFIG_SITE=$HOME/CONFIG_SITE, and then in $HOME/CONFIG_SITE, something like:

test "$prefix" = NONE && pfx=/usr/local || pfx=$prefix
: ${CPPFLAGS=-I$pfx/include}
: ${LDFLAGS=-L$pfx/lib}

This will insert appropriate flags to the compiler and linker to always look in some common locations.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

Most likely the paths /usr/local/include and /usr/local/lib are not searched by default by the compiler. You can do it be modifying the CFLAGS and LDFLAGS variables in your configure.ac script:

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

Add those two lines before you check for the header and library.

Possibly you might have to set CPPFLAGS (for the pre-processor) and CXXFLAGS (if you are building C++ code) as well, to add the include path.

Edit: To set these flags in configure.ac is, as noted by William Pursell, not really recommended. Instead you set the these as environment variables when invoking the generated configure script:

$ CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
0

There's always the AM_ICONV automake macro (iconv.m4) which is part of GNU gettext. You need not use gettext.m4.

ldav1s
  • 15,885
  • 2
  • 53
  • 56
  • When I added AM_ICONV to configure.ac, autoreconf will report me a message with "required file 'config.rpath' not found", and how to solve it?Thanks!! – MYMNeo Jul 28 '12 at 04:22
  • The 'config.rpath' file is part of GNU gettext also. You can copy that file to `AC_CONFIG_AUX_DIR` and it should work. – ldav1s Jul 30 '12 at 18:06