Have Autoconf manually check for library when there is no .pc file
Asked Answered
S

3

5

I'm relatively new to using Autoconf and so far I've only used PKG_CHECK_MODULES and that's worked for me. I've come across a package, specifically the Debian libmhash-dev v0.9.9.9-1, that doesn't include a .pc file for pkg-config to use.

How do I tell Autoconf to check for mhash and pass the correct flags onto g++?

Soracco answered 15/2, 2011 at 9:41 Comment(0)
B
4

Not sure if this is the place for this diatribe (pretty sure it's not!), but my learning curve for a long time has looked like: foo is a great idea, but a lot of the old luddites say its bad, but I'm going to use it because it's great. (wait a few months) Oh, no, the people who said foo was bad were right, but now I've got several months of work committed and I'll have a lot of extra work in front of me to fix it. Bummer.

In short, PKG_CHECK_MODULES is a bad idea, but you may not realize it until you have used it for several months (or years) and have a whole lot of code that depends on it. Save yourself trouble in the future, and start purging PKG_CHECK_MODULES from your configure.ac files today. Use AC_CHECK_LIB and AC_SEARCH_LIBS and AC_CHECK_FUNC, but do not use PKG_CHECK_MODULES.

pkg-config certainly has a place, and a savvy administrator can use it in a CONFIG_SITE or in scripts to help in setting up configure runs, but PKG_CHECK_MODULES should not be used.

Becalm answered 15/2, 2011 at 15:18 Comment(4)
Well, like you said, PKG_CHECK_MODULES looks so great. Why is it so bad and things like AC_CHECK_LIB (which looks horribly clunky), AC_SEARCH_LIBS and AC_CHECK_FUNC so great? Also, if PKG_CHECK_MODULE is so horrible, why is it there in the first place? Shouldn't it just be deprecated and then removed altogether as soon as they figured out it's bad?Soracco
@Tim PKG_CHECK_MODULES is provided by pkg-config, not by any of the autotools, so although the autoconf maintainer recommends against its use, he cannot remove it and deprecate it.Becalm
But I mean he'd be able to remove the macro, wouldn't he? At any rate, what is actually so bad about PKG_CHECK_MODULES?Soracco
@Tim Eric cannot remove the macro from pkg-config, because he is not the maintainer of pkg-config. He cannot remove it from your configure.ac, because he does not maintain your package. The two biggest complaints about PKG_CHECK_MODULES are that it adds a dependency on pkg-config (or forces the user to set PKG_CONFIG=true) and that it tests version numbers rather than features. (I find neither of these arguments compelling.) IMO, the main problem is that it doesn't actually add anything useful. However, many people complain that it leads to subtle build errors on less popular platforms.Becalm
E
3

But it's better to use AC_SEARCH_LIBS - as manual advises.

Exhaustive answered 15/2, 2011 at 13:59 Comment(0)
A
0

Use AC_CHECK_LIB.

Atalya answered 15/2, 2011 at 13:52 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Avion
I usually offer some explanation, but if the answer is simply 'take a better look at the documentation,' as in this case, then I don't think it's so bad because a) it's the official documentation and unlikely to change and b) if it does, it's easy to search for the macro name and get to the new official documentation.Atalya

© 2022 - 2024 — McMap. All rights reserved.