7 Reeds
7 Reeds

Reputation: 2539

autotools: one project with one executable, one shared obj and a "shared" internal library

I am trying my hand at autotools. I have the following project hierarchy:

    project/src
    project/src/utilities
    project/src/utilities/util.c
    project/src/utilities/util.h
    project/src/sharedObject
    project/src/sharedObject/sharedObject.c
    project/src/sharedObject/sharedObject.h
    project/src/sharedObject/thing.c
    project/src/executable
    project/src/executable/exec.c
    project/src/executable/exec.h
    project/src/executable/thing1.c
    project/src/executable/thing2.c

"executable" and "sharedObject.so" both depend on "util.o" and "util.h". I have seen examples of creating convenience libraries but I am not sure how to specify them in the "Makefile.am" files in the other two sub-projects. How are these kinds of inter-project dependencies defined?

Both "executable" and "sharedObject.so" will be installed. The "util.o" and "util.h" files will only be used in the build process.

Thank you

Upvotes: 3

Views: 908

Answers (1)

Brett Hale
Brett Hale

Reputation: 22318

In the utilities/Makefile.am:

noinst_LTLIBRARIES = libutil.la   
libutil_la_SOURCES = util.h util.c

In executable/Makefile.am, the use of the library should use the LDADD primary, e.g.,

bin_PROGRAMS = exec
exec_SOURCES = exec.h exec.c thing.h thing.c
exec_LDADD = ../utilities/libutil.la

In sharedObject/Makefile.am, use the LIBADD primary:

lib_LTLIBRARIES = sharedObject.la
sharedObject_la_SOURCES = sharedObject.h sharedObject.c thing.c
sharedObject_la_LIBADD = ../utilities/libutil.la

If you actually want a sharedObject.so that is to be dynamically loaded, you also need:

sharedObject_la_LDFLAGS = -module

Otherwise, the target should be called libsharedObject.


The top level Makefile.am should order SUBDIRS so that the dependency is built first:

SUBDIRS = utilities executable sharedObject

Upvotes: 3

Related Questions