How to install LDFLAGS for noinst library in Automake?

Suppose I 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 is dependent on other libs. To prevent getting help errors undefined, I need to configure the LDFLAGS variable. Here is what I did:

 libfoo_a_LDFLAGS = `pkg-config --ldflags some_lib` 

However, the machine does not work 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 .

+4
source share
1 answer

This cannot be done using the simple * .a middleware library. This is because the middleware is never linked, so LDFLAGS doesn't make sense to it. An intermediate library is just an archive archive, which is just a collection of object files. There is no place in the ar archive for writing flags that will need to be used to bind the final object.

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

Another possibility is to create your intermediate libraries as libtool * .la libraries, although you will only use them as intermediate libraries. When you do this, the assembly system will generate a shared object (which you ultimately do not use, since you will combine the base object files into the actual assembly artifact), but more importantly, it will create a * .la file that has space for recording such kind of dependency information. The Automake manual calls it the Libtool Convenience Library. To do this, you need to use libtool, of course, and switch to calling this libfoo.la in Makefile.am and list it in noinst_LTLIBRARIES . But if you are not already using libtool, this is probably more of a problem than it costs.

+5
source

All Articles