Reputation: 12960
I've stumbled over a seemingly simple problem while building two libraries and test programs for both.
The Problem: I have two static libraries, libA and libB, and libB depends on libA. I don't want to explicitly link all programs that use libB to libA, I want SCons to see that if a program links to library B it should link to library A as well.
I've built a simple example that illustrates this problem. Since I couldn't find a suitable file hoster and this is programming related, I created a small SVN repository:
svn checkout https://example-repository.googlecode.com/svn/trunk example-repository
or you can download a tarball here.
Upvotes: 5
Views: 1278
Reputation: 1312
SCons does not have built in support for expressing transitive library dependencies as you describe, but its younger cousin Waf does. See the documentation for the "use" feature in the Waf book. The Boost build system also has this feature under a different name. You can also choose to implement this yourself in SCons if you are willing to code a little bit of Python.
One trick you can use is the ability to define callbacks as construction variables (ie. strings that will be expanded through a Python function call). Have that function call compute the transitive list of libraries you need based on some form of dependency graph you compute at parse time (ie. through method calls found in SConscripts), and you will not have to repeat the full list of libraries for every target or environment.
Upvotes: 4
Reputation: 336
What are libB and libA? Are they libs that are one big .o or are they made up of several .o files?
If the libs are multiple .o files and you are calling a function in one of libB's .o files that uses one of libA's .o files, then you get the libB's .o and the dependent libA .o. If you are using a function in a libB .o that does not depend on anything from libA, then you only get the libB .o file in your binary.
Thus, if you have the command:
cc -o a.out a.c libA.a libB.a
You will only get the parts needed from both libB and libA.
Upvotes: 0