[Scons-users] Question about paths and shared libraries with SCons

Ted Middleton tmiddleton at teradici.com
Mon Jul 23 14:06:00 EDT 2012


I'm using scons to build an executable and several dlls (.so's) that it depends on. In my root SConsctruct file I have roughly this:

dylibs = []
dylibs += SConscript( dirs='foodir', exports=['env'] )
dylibs += SConscript( dirs='bardir', exports=['env'] )
exe = SConscript( dirs='exedir', exports= { 'env' : env, 'dyibs' : dylibs } )

and then in exedir/SConscript I have

Import('env', 'dylibs')
prog = env.Program( 'program', source=['main.cpp', dylibs] )
Return('prog')

Scons ends up building them like this:

gcc -o exedir/program foodir/libfoo.so bardir/libbar.so

It seems that whenever scons wants to coerce a scons Node object to a string to build a command line, it likes everything to be relative to that root SConstruct file (which makes sense). If the SConstruct file had been in exedir, I would imagine that the command line that scons would build would look something like this:

gcc -o program ../foodir/libfoo.so ../bardir/libbar.so -Wl,rpath=/opt/mycompany/lib

How is this a problem? ld will embed whatever .so filename you put on the path that gcc gets invoked with. So in the first example, the actual reference embedded in exedir/program is foodir/libfoo.so and bardir/libbar.so, rather than just libfoo.so and libbar.so. In the second case ../foodir/libfoo.so and ../bardir/libbar.so get embedded in exedir/program.

Any ideas on what the most elegant way of dealing with this would be? I could hack it and change the code in exedir/SConscript to something like this:

Import('env', 'dylibs')
prog = env.Program( 'program', source=['main.cpp', dylibs] )
Return('prog')
dylibnames = [ a[0].name for a in dylibs ]
dylibpaths = [ a[0].Dir('.').abspath for a in dylibs ]
senv=env.Clone()
senv.Append( LIBS=dylibnames )
senv.Append( LIBPATH=dylibpaths )
prog = senv.Program( 'program', source=['main.cpp'] )
Return('prog')

It's just that that doesn't seem very scons-y anymore. Can someone set me straight here?

















More information about the Scons-users mailing list