Discussion:
Having trouble using AC_CHECK_LIB
Julian Marchant
2015-03-02 01:38:21 UTC
Permalink
I'm trying to replace the hand-made Makefile of Project: Starfighter
with Autoconf and Automake files. This is my first time using Autoconf
and Automake, so I'm kind of learning as I go along.

I'm stuck at one part. Project: Starfighter requires SDL_Image and
SDL_Mixer from SDL2 in order to build, so I'm trying to check for them
by using AC_CHECK_LIB with functions defined by SDL_Image and
SDL_Mixer. These are my checks (you can see the attached file for the
full configure.ac):

AC_CHECK_LIB([SDL2], [SDL_Init], [], [echo "Error: SDL2 not
found." ; exit 1])
AC_CHECK_LIB([SDL2], [IMG_Load], [], [echo "Error: SDL_Image not
found." ; exit 1])
AC_CHECK_LIB([SDL2], [Mix_LoadWAV], [], [echo "Error: SDL_Mixer
not found." ; exit 1])

When I generate and run a configure script, the first check always
passes, but the second and third always fail (I checked the third by
removing the exit call from the second one). But I know I have
SDL_Image and SDL_Mixer for SDL2, because I can compile Project:
Starfighter with the hand-made Makefile (attached) just fine.

So, I suppose I have two questions:

1. Am I doing something I shouldn't be doing? (e.g. is it bad to check
a library more than once?)

2a. If so, what am I supposed to do to check for something like
SDL_Image and SDL_Mixer (where it's in the same library, but
separately packaged)?

2b. If not, how can I figure out what's wrong?

- --
Julian Marchant
https://onpon4.github.io

Protect your privacy with GnuPG:
https://emailselfdefense.fsf.org
Harlan Stenn
2015-03-02 06:10:23 UTC
Permalink
Post by Julian Marchant
I'm trying to replace the hand-made Makefile of Project: Starfighter
with Autoconf and Automake files. This is my first time using Autoconf
and Automake, so I'm kind of learning as I go along.
I'm stuck at one part. Project: Starfighter requires SDL_Image and
SDL_Mixer from SDL2 in order to build, so I'm trying to check for them
by using AC_CHECK_LIB with functions defined by SDL_Image and
SDL_Mixer. These are my checks (you can see the attached file for the
AC_CHECK_LIB([SDL2], [SDL_Init], [], [echo "Error: SDL2 not
found." ; exit 1])
AC_CHECK_LIB([SDL2], [IMG_Load], [], [echo "Error: SDL_Image not
found." ; exit 1])
AC_CHECK_LIB([SDL2], [Mix_LoadWAV], [], [echo "Error: SDL_Mixer
not found." ; exit 1])
AC_CHECK_LIB is OK, and AC_SEARCH_LIBS might be better.

Don't use echo like that.

Do the AC_CHECK_LIB and after it's done check ac_cv_lib_SDL_Init or
other values, and if those are missing call AC_MSG_ERROR to note your
error condition and exit.

Or if you use AC_SEARCH_LIBS use ac_cv_search_SDL_Init (or whatever) and
check that way.

http://www.gnu.org/software/autoconf/manual/autoconf.html#Libraries

H
Gavin Smith
2015-03-02 09:38:01 UTC
Permalink
Post by Harlan Stenn
Post by Julian Marchant
I'm stuck at one part. Project: Starfighter requires SDL_Image and
SDL_Mixer from SDL2 in order to build, so I'm trying to check for them
by using AC_CHECK_LIB with functions defined by SDL_Image and
SDL_Mixer. These are my checks (you can see the attached file for the
AC_CHECK_LIB([SDL2], [SDL_Init], [], [echo "Error: SDL2 not
found." ; exit 1])
AC_CHECK_LIB([SDL2], [IMG_Load], [], [echo "Error: SDL_Image not
found." ; exit 1])
AC_CHECK_LIB([SDL2], [Mix_LoadWAV], [], [echo "Error: SDL_Mixer
not found." ; exit 1])
AC_CHECK_LIB is OK, and AC_SEARCH_LIBS might be better.
Don't use echo like that.
Do the AC_CHECK_LIB and after it's done check ac_cv_lib_SDL_Init or
other values, and if those are missing call AC_MSG_ERROR to note your
error condition and exit.
Or if you use AC_SEARCH_LIBS use ac_cv_search_SDL_Init (or whatever) and
check that way.
http://www.gnu.org/software/autoconf/manual/autoconf.html#Libraries
I'd argue this is a failing of the autoconf manual. It lacks a simple
example of checking the "ac_cv_lib_LIBRARY_FUNCTION" after the use of
AC_CHECK_LIB. Even if the writer of configure.ac understands they can
check this variable, it's not easy to work out how to check the
variable in portable shell script with the help of autoconf macros.

It's not obvious from the autoconf manual what a "cache variable"
should be used for in any case. It gives the impression that they are
mainly used for speeding up the run:
http://www.gnu.org/software/autoconf/manual/autoconf.html#Caching-Results.
This leads a reader to think they can be ignored up until the point
when the configure is taking too long to run. It's not obvious that
they are shell variables accessible in the configure.ac script, and
that checking their values is needed/encouraged.

The ordering of the information in
http://www.gnu.org/software/autoconf/manual/autoconf.html#Results
makes it difficult to understand what is done with the results of
tests. Section 7.1 "Defining C Preprocessor Symbols" refers to "cache
variables", but if you were reading this chapter in order, you
wouldn't learn about cache variables until section 7.4. (It also
refers to "output variables", which aren't explained until section
7.2.)
Julian Marchant
2015-03-02 13:32:50 UTC
Permalink
Well, doing a search, I came across something that showed me that I'm
supposed to check for the "SDL_image" library for SDL_image, so I
changed "SDL2" in that check to "SDL2_image", and it worked. But I'm
confused now; what's the rule for what the library is called? I
thought it was the -l option you use without "-l", but you use -lSDL2
for SDL2/SDL_image.h... right? At least, this works with the hand-made
Makefile when building on my system.

- --
Julian Marchant
https://onpon4.github.io

Protect your privacy with GnuPG:
https://emailselfdefense.fsf.org
Julian Marchant
2015-03-02 13:48:56 UTC
Permalink
OK, I see where my confusion is. The makefile gets -lSDL2_image and
- -lSDL2_mixer out of a call to pkg-config. Now I've got to figure out
why searching for SDL2_mixer is failing... but I've got some things to
check in that regard.

Anyway, thanks for the tip on not using echo that way. For the record,
I got the idea to do that from here:

http://amjith.blogspot.com/2009/04/autoconf-and-automake-tutorial.html?_escaped_fragment_=#!

- --
Julian Marchant
https://onpon4.github.io

Protect your privacy with GnuPG:
https://emailselfdefense.fsf.org
Mike Frysinger
2015-03-02 20:50:17 UTC
Permalink
Post by Julian Marchant
OK, I see where my confusion is. The makefile gets -lSDL2_image and
-lSDL2_mixer out of a call to pkg-config. Now I've got to figure out
why searching for SDL2_mixer is failing... but I've got some things to
check in that regard.
if the libraries provide pkg-config files, you should use those instead of
probing things directly with AC_CHECK_LIB. i.e. use the PKG_CHECK_MODULES
macro instead.
-mike
Julian Marchant
2015-03-02 23:14:27 UTC
Permalink
Post by Mike Frysinger
if the libraries provide pkg-config files, you should use those
instead of probing things directly with AC_CHECK_LIB. i.e. use the
PKG_CHECK_MODULES macro instead.
It doesn't; it just does this:

LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer`

The command that's parsed for the assignment to LIBS returns
"-lSDL2_image -lSDL2_mixer -lSDL2".

- --
Julian Marchant
https://onpon4.github.io

Protect your privacy with GnuPG:
https://emailselfdefense.fsf.org
Zack Weinberg
2015-03-02 23:19:00 UTC
Permalink
Post by Julian Marchant
Post by Mike Frysinger
if the libraries provide pkg-config files, you should use those
instead of probing things directly with AC_CHECK_LIB. i.e. use the
PKG_CHECK_MODULES macro instead.
LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer`
If this works, PKG_CHECK_MODULES will work too; that's what Mike was
trying to say.
Julian Marchant
2015-03-02 23:53:58 UTC
Permalink
Post by Zack Weinberg
If this works, PKG_CHECK_MODULES will work too; that's what Mike
was trying to say.
Ah, OK. Where's the documentation on that macro? I don't see it on
https://www.gnu.org/software/autoconf/manual/autoconf.html.

- --
Julian Marchant
https://onpon4.github.io

Protect your privacy with GnuPG:
https://emailselfdefense.fsf.org
Peter Johansson
2015-03-03 00:04:58 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Zack Weinberg
If this works, PKG_CHECK_MODULES will work too; that's what Mike
was trying to say.
Ah, OK. Where's the documentation on that macro? I don't see it on
https://www.gnu.org/software/autoconf/manual/autoconf.html.
It's part of pkg-config

http://www.freedesktop.org/wiki/Software/pkg-config/

Cheers,
Peter
--
Peter Johansson
Loading...