[Scons-users] Automatically add library when using header file?
Andrew C. Morrow
andrew.c.morrow at gmail.com
Sat Mar 14 12:04:59 EDT 2020
I have thought about doing something like this before. My rough idea about
how to do this would look like:
If bar.c (maybe bar.o, in practice) depends on foo.h, then foo would get
added to bar's libraries. This would work by adding an emitter to
[Shared]Library which would add the libfoo target node to some new entry on
the .attributes for the Node of each header in LIBHEADERS. Then add a new
Scanner to Program and SharedLibrary that walked the children, and found
header files that had the attribute, accumulating the library nodes
associated with the header into a list of libraries.
However, I see several potential issues with this:
- Including a header shouldn't necessarily induce a link edge. You might,
for instance, have included the header only for a constant.
- I have a suspicion that the header graph has potential complexities that
would lead to erroneous or cyclic induced library dependencies, though I
haven't really sat down and proved it.
- You would really want to be using something like IWYU to ensure that a
stale header inclusion didn't introduce a link edge that should no longer
- It isn't clear exactly how such a tool should add the library. Some
projects use search paths (-L) to find libraries, others name them as files
by path. Some projects use LIBS, others, like MongoDB have LIBDEPS. So
there would need to be some user provided customization hook that mapped
from "Node to link to" to "expansion on the command line".
- Presumably, you would want transitivity of some sort. Maybe it falls out
automatically, maybe it doesn't.
- I have some worries about how this approach would work w.r.t. the SCons
- The child walk might be very slow.
So, overall, I think it is a pretty tricky thing to do right.
On Tue, Mar 10, 2020 at 8:52 PM Bill Deegan <bill at baddogconsulting.com>
> Not currently.
> Pull requests welcome.. ;)
> On Tue, Mar 10, 2020 at 12:00 PM Daan De Meyer <daan.j.demeyer at gmail.com>
>> Is there a way to associate header files with a library so that the
>> library is automatically added to the link options of any executable that
>> uses header files from that library? I've looked around in the guide and on
>> the internet but haven't found a solution.
>> Daan De Meyer
>> Scons-users mailing list
>> Scons-users at scons.org
> Scons-users mailing list
> Scons-users at scons.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Scons-users