Top-Level Path Names in Subsidiary SConscript Files

If you need to use a file from another directory, it's sometimes more convenient to specify the path to a file in another directory from the top-level SConstruct directory, even when you're using that file in a subsidiary SConscript file in a subdirectory. You can tell SCons to interpret a path name as relative to the top-level SConstruct directory, not the local directory of the SConscript file, by appending a # (hash mark) to the beginning of the path name:

       env = Environment()
       env.Program('prog', ['main.c', '#lib/foo1.c', 'foo2.c'])
    

In this example, the lib directory is directly underneath the top-level SConstruct directory. If the above SConscript file is in a subdirectory named src/prog, the output would look like:

       % scons -Q
       cc -o lib/foo1.o -c lib/foo1.c
       cc -o src/prog/foo2.o -c src/prog/foo2.c
       cc -o src/prog/main.o -c src/prog/main.c
       cc -o src/prog/prog src/prog/main.o lib/foo1.o src/prog/foo2.o
    

(Notice that the lib/foo1.o object file is built in the same directory as its source file. See the chapter called Separating Source and Build Directories, below, for information about how to build the object file in a different subdirectory.)