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

Chris BeHanna chris at behanna.org
Tue Aug 21 11:46:34 EDT 2012


On Aug 21, 2012, at 10:43 , Gary Oberbrunner <garyo at oberbrunner.com> wrote:


> On Tue, Aug 21, 2012 at 11:30 AM, Chris BeHanna <chris at behanna.org> wrote:

>> On Aug 21, 2012, at 07:44 , Gary Oberbrunner <garyo at oberbrunner.com> wrote:

>>

>>> On Tue, Aug 21, 2012 at 4:50 AM, Ted Middleton <tmiddleton at teradici.com> wrote:

>>> ...

>>>> [...difficulties getting paths set up right for link command...]

>>

>> In the OP's case, it's simpler--he's building a shared library and not linking it against anything. There is no need to set LIBPATH or LIBS at all for that (although it is harmless to have LIBPATH set), unless the .so is getting linked against its dependency shared libraries (a practice I HIGHLY recommend). This will do just fine (the bit with the '#' character is significant--it means "anchor this path to the top of the build instead of computing it relative to the SConscript file in which it appears"):

>>

>> # Assume a prior setting of LIBPATH

>> env.Append(LIBPATH = [os.path.join('#', Dir('.').path])

>>

>> env.Append(CPPPATH = [os.path.join('#', Dir('.').path])

>> env.SharedLibrary('foo', 'foo.cpp')

>>

>> This will generate

>>

>> g++ -o foodir/libfoo.so -I/path/to/foodir foodir/foo.cpp \

>> -L/path/to/foodir

>

> Yes, that sounds just right. (BTW, why do you do os.path.join('#',

> Dir('.').path? Isn't that equivalent to just '.'?)


In SCons 1.2, I had difficulties with the paths getting expanded relative to the SConscript in which they appeared. Doing the path join guarantees that the path gets anchored to the top of the tree, so that no matter where it might be referenced later (e.g., in some different sibling subdirectory of the build), it gets expanded and referenced correctly.

Consider the difference between

env.Append(LIBPATH = ['foo'])

and

env.Append(LIBPATH = [os.path.join('#', 'foo')])

This is a gotcha that will drive you nuts.

--
Chris BeHanna
chris at behanna.org


More information about the Scons-users mailing list