Question

Suppose I have developed libfoo.a as an intermediate step in my compilation process. Here is the line for it in Makefile.am:

noinst_LIBRARIES = libfoo.a

This lib depends on other libs. To prevent me from getting undefined reference errors, I need to setup its LDFLAGS variable. Here is what I did:

libfoo_a_LDFLAGS = `pkg-config --ldflags some_lib`

However, automake fails with this message:

variable `libfoo_a_LDFLAGS` is defined but no program or library has `libfoo_a` as canonical name (possible typo)

What am I doing wrong here? It works for libfoo_a_SOURCES and _CFLAGS.

Was it helpful?

Solution

It's not possible to do this using a simple *.a intermediate library. That's because an intermediate library is never linked, so LDFLAGS is not meaningful for it. The intermediate library is just an ar archive, which is only a collection of object files. The ar archive has no place to record the flags that would need to be used for linking the final object.

The normal solution is to do what William Pursell suggests: add the necessary LDFLAGS to the final executables or shared libraries that you create in your build process.

Another possibility is to build your intermediate libraries as libtool *.la libraries, even though you are only going to use them as intermediate libraries. When you do this, the build system will generate a shared object (which you will then end up not using, since you'll combine the underlying object files into your actual build artifact), but more importantly it will create a *.la file, which has a place to record this sort of dependency information. The Automake manual calls this a "Libtool Convenience Library". To do this, you have to use libtool, of course, and switch over to calling this libfoo.la in your Makefile.am and list it in noinst_LTLIBRARIES. But unless you're already using libtool, this is probably more trouble than it's worth.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top