rkemp
rkemp

Reputation: 278

Scons: How to create LIB dependency when using variable subsitution

So I want to build a Program and link to Shared Libraries. The Shared Libraries themselves have their own dependencies. I'm trying to make it so that I only have to specify the direct shared library dependencies on the Program's SConscript, and not what the shared library themselves depend on, which would be captured in their own SConscripts.

Thus, if a base library creates a dependency that 40 Programs sprinkled throughout the codebase depend, all 40 SConscript files don't have to be updated to reflect the addition of the new lib dependency. It should be inherited automatically.

To illustrate the situation, let's say I have two Shared Library projects (projA and projB). ProjA requires a couple of boost libs, and projB requires another set of boost libs. If I want to build a Program that depends on the projA and projB shared libraries, I want to specify a LIBS= variable that only includes projA and projB, but will resolve to all the needed libs when the action is called (thus picking up the boost libs that each depends on).

However, when I do this with variable subsitution, scons is not identifying the dependencies correctly, and therefore scons is not building the libraries (projA, and projB). Repeated calls to scons will eventually build everything, so it's as if it doesn't quite make all the dependency connections on the first pass.

How do I get scons to detect the dependencies when using variable substitution in the Program builder LIBS= line.

Update: After invoking scons repeatedly it will eventually build everything and link correctly. It appears that scons correctly identifies the dependencies, as the libs show up when using the scons --tree=derived,prune option, but this only works when there are no build errors, so only after repeated invocations of scons and we finally have everything built.

The error that I receive is a library not found linker error. The libraries are not built, so there error makes sense. But why are the libs not built, scons does pick them up as reported in the -tree option?

Sample SConscript below:


ProjA/SConscript:

Import('env')
TARGET = 'projA'
LIBS = [
 'boost_date_time'
 'boost_filesystem'
]
TARGET_LIBS = 'LIBS_' + TARGET
env[TARGET_LIBS] = [TARGET, LIBS]
env.SharedLibrary(
    target = TARGET,
    source = projA.cpp
)

ProjB/SConscript:

Import('env')
TARGET = 'projb'
LIBS = [
 'boost_thread'
 'boost_serialization'
]
TARGET_LIBS = 'LIBS_' + TARGET
env[TARGET_LIBS] = [TARGET, LIBS]
env.SharedLibrary(
    target = TARGET,
    source = projB.cpp
)

MyExecutable/SConscript:

TARGET = 'myExecutable'
LIBS = [
  '$LIBS_other_projA',
  '$LIBS_other_projB',
]

env.Program(
    target  = TARGET,
    LIBS    = LIBS, # this should interploate to projA, boost_date_time, boost_filesystem, projB, boost_thread, boost_serialization (which it does, but it doesn't create all the dependencies immediately, so projB doesn't get built, requires a second invocation
    source  = myExecutable.cpp
)

Upvotes: 0

Views: 448

Answers (1)

rkemp
rkemp

Reputation: 278

After upgrading to scons version 2.4.1, this issue is now solved.

Upvotes: 0

Related Questions