In my project I have some shared code in a statically linked library that is used by several subprojects, each of which building its own executable. I use ar
to create the library from the .o
files. Part of the shared code depends on statically linked third party libraries.
Currently, I have to include all the third party libraries in each makefile (for each executable) and pass them to g++
. Is it possible to include these libraries in the one library shared by the subproject, so I don't have to reference them explicitly when building the different executables? Or is there something wrong with my approach in general?
It is possible to pack all the static libraries you are using in one big library. You don't want that.
The common method of dealing with the situation is defining variables in your top level makefile, or in an .inc file included by several makefiles:
MY_LIBS = -lOne -lTwo
MY_LDFLAGS = -L /path/to/libs
and then adding these variables to standard variables
LDLIBS += $(MY_LIBS)
LDFLAGS += $(MY_LDFLAGS)
Variables above are used by GNU Make implicit link rules; if you are using your own rules, be sure to use these variables, like this:
...
g++ $^ $(LDLIBS) $(LDFLAGS) -o $@
Look at several makefiles from established open source projects for inspiration.
References:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments