1

My project requires dependency of libxml2 am using autotools to check the dependencies & install the same. I declare the dependency of using the following macro in configure.ac

echo -n "checking if libxml2 is present... "

PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.19],
              [echo "yes (features requiring libxml2 enabled)"  AC_DEFINE(HAVE_LIB_XML, 1,     [define if libxml2 is present])],
              [echo "no"] )

The macro works as desired in GNU/Linux.

But somehow it fails in Solaris with the following error

checking if libxml2 is present... ./configure: line 11586: syntax error near unexpected token `LIBXML2,'
./configure: line 11586: `PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= 2.6.19,'

Googled for a solution, most of them complain of pkg-config not being installed. But in my test machine its actually installed, checked it by executing the following command.

bash-3.00# pkg-config libxml-2.0 --modversion
2.6.23

Some suggestions would be welcomed.

ldav1s
  • 15,885
  • 2
  • 53
  • 56
Cuurious
  • 107
  • 2
  • 10
  • What version of autotools are on your Solaris box? What version of autotools are on your GNU/Linux box? – ldav1s Jul 20 '11 at 20:11
  • Remark: `echo -n` is non-portable. `PKG_CHECK_MODULES` emits its own "checking" messages, but if you still want yours, use `AC_MSG_CHECKING`. – Jack Kelly Jul 21 '11 at 00:45
  • 2
    Why are you running the autotools on both boxes? You should run the autotools on only one machine, and then check the distribution tarball on both. Ideally, you can run autotools on either box, but in your case it looks like your autotool chain is broken on Solaris (the pkg config macros are not being located by aclocal). Two pieces of advice: 1) stop running autoconf on Solaris, 2) stop using PKG_CHECK_MODULES. – William Pursell Jul 21 '11 at 09:14
  • @William: One possible case is development work against the svn HEAD (or similar) on both GNU/Linux and Solaris. – Jack Kelly Jul 23 '11 at 01:48
  • @Jack Do you mean a scenario in which all of the derived files are stored in the repository, with a branch for each platform? (That seems like a disaster!) If it is necessary to generate a different configure script for each platform, then the whole function of testing the platform for features (the main point of the configure script) is moot! – William Pursell Jul 23 '11 at 09:52
  • @William: Not at all! I mean that you're doing dev on both Solaris and GNU/Linux, in which case you need to be able to bootstrap the build system after you checkout. – Jack Kelly Jul 23 '11 at 11:35

1 Answers1

8

The PKG_CHECK_MODULES macro doesn't seem to be expanded properly. When you installed pkg-config, did it install pkg.m4 (in somewhere like /usr/share/aclocal)? If so, try running aclocal again (maybe with -I m4, if you've got custom m4 code in the m4 subdirectory) and then run autoconf.

If that doesn't work and pkg.m4 was installed, try running autoreconf -f (and maybe autoreconf -i -f).

If that doesn't work, you'll need to copy pkg.m4 to a directory for your package. Usually this is the m4 subdirectory. Set ACLOCAL_AMFLAGS = -I m4 (or ACLOCAL_AMFLAGS = -I m4 --install) in Makefile.am (if you're using automake), and AC_CONFIG_MACRO_DIR([m4]) in configure.ac. Then run aclocal -I m4 and autoconf and ./configure.

Jack Kelly
  • 18,264
  • 2
  • 56
  • 81
  • thanks its working fine, the pkg.m4 was installed in /usr/local/share/aclocal/ rather than the path you specifie, – Cuurious Jul 27 '11 at 12:33
  • I had the same problem in OmniOS 151010, I solved it by creating a symling of `pkg.m4` to `/usr/share/aclocal/pkg.m4` (original file was in `/opt/omni/share/aclocal/pkg.m4`) – Vincenzo Pii Aug 06 '14 at 14:47