Finding Libraries: the LIBPATH Construction Variable

By default, the linker will only look in certain system-defined directories for libraries. SCons knows how to look for libraries in directories that you specify with the LIBPATH construction variable. LIBPATH consists of a list of directory names, like so:

      env = Environment(LIBS = 'm',
                        LIBPATH = ['/usr/lib', '/usr/local/lib'])
      env.Program('prog.c')
    

Using a Python list is preferred because it's portable across systems. Alternatively, you could put all of the directory names in a single string, separated by the system-specific path separator character: a colon on POSIX systems:

      LIBPATH = '/usr/lib:/usr/local/lib'
    

or a semi-colon on Windows systems:

      LIBPATH = 'C:\lib;D:\lib'
    

When the linker is executed, SCons will create appropriate flags so that the linker will look for libraries in the same directories as SCons. So on a POSIX or Linux system, a build of the above example would look like:

      % scons
      cc -c prog.c -o prog.o
      cc -o prog -L/usr/lib -L/usr/local/lib -lm prog.o
    

On a Windows system, a build of the above example would look like:

      C:\>scons
      cl /Foprog.obj prog.c
      link /nologo /OUT:program.exe /LIBPATH:\usr\lib;\usr\local\lib m.lib prog.obj
    

Note again that SCons has taken care of the system-specific details of creating the right command-line options.