It's common to re-use code by sharing source files between multiple programs. One way to do this is to create a library from the common source files, which can then be linked into resulting programs. (Creating libraries is discussed in Chapter 4, Building and Linking with Libraries, below.)
Usually, you build a library because you want to link it with one or more programs. You link libraries with a program by specifying the libraries in the $LIBS construction variable, and by specifying the directory in which the library will be found in the $LIBPATH construction variable:
For example, suppose that you want to create a file every time you run a build that identifies the time the build was performed, the version number, etc., and which is included in every program that you build. The version file's contents will change every build. If you specify a normal dependency relationship, then every program that depends on that file would be rebuilt every time you ran SCons. For example, we could use some Python code in a SConstruct file to create a new version.c file with a string containing the current date every time we run SCons, and then link a program with the resulting object file by listing version.c in the sources:
It is rare that all of the software in a large, complicated system needs to be built exactly the same way. For example, different source files may need different options enabled on the command line, or different executable programs need to be linked with different libraries. SCons accommodates these different build requirements by allowing you to create and configure multiple construction environments that control how the software is built. A construction environment is an object that has a number of associated construction variables, each with a name and a value, just like a dictionary. (A construction environment also has an attached set of Builder methods, about which we'll learn more later.)
Configuring the right options to build programs to work with libraries--especially shared libraries--that are available on POSIX systems can be complex. To help this situation, various utilies with names that end in config return the command-line options for the GNU Compiler Collection (GCC) that are needed to build and link against those libraries; for example, the command-line options to use a library named lib could be found by calling a utility named lib-config.
One use of the SetOption function is to specify a value for the -j or --jobs option, so that you get the improved performance of a parallel build without having to specify the option by hand. A complicating factor is that a good value for the -j option is somewhat system-dependent. One rough guideline is that the more processors your system has, the higher you want to set the -j value, in order to take advantage of the number of CPUs.
For example, suppose the administrators of your development systems have standardized on setting a NUM_CPU environment variable to the number of processors on each system. A little bit of Python code to access the environment variable and the SetOption function provides the right level of flexibility:
If a shared library is created with the $SHLIBVERSION variable set, scons will create symbolic links as needed based on that variable. To properly install such a library including the symbolic links, use the InstallVersionedLib function.
Will produce a shared library libfoo.so.1.2.3 and symbolic links libfoo.so and libfoo.so.1 which point to libfoo.so.1.2.3. You can use the Node returned by the SharedLibrary builder in order to install the library and its symbolic links in one go without having to list them individually:
On systems which expect a shared library to be installed both with a name that indicates the version, for run-time resolution, and as a plain name, for link-time resolution, the InstallVersionedLib function can be used. Symbolic links appropriate to the type of system will be generated based on symlinks of the source library.
The order of the -I options replicates, for the C preprocessor, the same repository-directory search path that SCons uses for its own dependency analysis. If there are multiple repositories and multiple $CPPPATH directories, SCons will add the repository directories to the beginning of each $CPPPATH directory, rapidly multiplying the number of -I flags. If, for example, the $CPPPATH contains three directories (and shorter repository path names!):
There are a few possible strategies for failing configure checks. Some checks may be for features without which you cannot proceed. The simple approach here is just to exit SCons at that point - a number of the examples in this chapter are coded that way. If there are multiple hard requirements, however, it may be friendlier to the user to set a flag in case of any fails of hard requirements and accumulate a record of them, so that on the completion of the configure context they can all be listed prior to failing the build - as it can be frustrating to have to iterate through the setup, fixing one new requirement each iteration. Other checks may be for features which you can do without, and here the strategy will usually be to set a construction variable which the rest of the build can examine for its absence/presence, or to set particular compiler flags, library lists, etc. as appropriate for the circumstances, so you can proceed with the build appropriately based on available features.
A custom check is a Python function that checks for a certain condition to exist on the running system, usually using methods that SCons supplies to take care of the details of checking whether a compilation succeeds, a link succeeds, a program is runnable, etc. A simple custom check for the existence of a specific library might look as follows:
The Visual C++ compiler option that SCons uses by defaultto generate PDB information is /Z7.This works correctly with parallel (-j) buildsbecause it embeds the debug information in the intermediate object files,as opposed to sharing a single PDB file between multiple object files.This is also the only way to get debug informationembedded into a static library.Using the /Zi instead may yield improvedlink-time performance,although parallel builds will no longer work.
Used to override $SHLIBNOVERSIONSYMLINKS/$LDMODULENOVERSIONSYMLINKS when creating versioned import library for a shared library/loadable module. If not defined,then $SHLIBNOVERSIONSYMLINKS/$LDMODULENOVERSIONSYMLINKS is used to determinewhether to disable symlink generation or not.
The prefix used for import library names. For example, cygwin uses importlibraries (libfoo.dll.a) in pair with dynamic libraries(cygfoo.dll). The cyglink linker sets$IMPLIBPREFIX to 'lib' and $SHLIBPREFIXto 'cyg'.
The suffix used for import library names. For example, cygwin uses importlibraries (libfoo.dll.a) in pair with dynamic libraries(cygfoo.dll). The cyglink linker sets$IMPLIBSUFFIX to '.dll.a' and $SHLIBSUFFIXto '.dll'.
When this construction variable is defined, a versioned loadable moduleis created by LoadableModule builder. This activates the$_LDMODULEVERSIONFLAGS and thus modifies the $LDMODULECOM asrequired, adds the version number to the library name, and creates the symlinksthat are needed. $LDMODULEVERSION versions should exist in the sameformat as $SHLIBVERSION.
An automatically-generated construction variablecontaining the linker command-line optionsfor specifying directories to be searched for library.The value of $_LIBDIRFLAGS is createdby respectively prepending and appending $LIBDIRPREFIXand $LIBDIRSUFFIXto each directory in $LIBPATH.
The prefix used to specify a library directory on the linker command line.This will be prepended to each directoryin the $LIBPATH construction variablewhen the $_LIBDIRFLAGS variable is automatically generated.
The suffix used to specify a library directory on the linker command line.This will be appended to each directoryin the $LIBPATH construction variablewhen the $_LIBDIRFLAGS variable is automatically generated.
The prefix used to specify a library to link on the linker command line.This will be prepended to each libraryin the $LIBS construction variablewhen the $_LIBFLAGS variable is automatically generated.
General user options passed to the linker.Note that this variable shouldnotcontain-l(or similar) options for linking with the libraries listed in $LIBS,nor-L(or similar) library search path optionsthat scons generates automatically from $LIBPATH.See$_LIBFLAGSabove,for the variable that expands to library-link options,and$_LIBDIRFLAGSabove,for the variable that expands to library search path options.See also $SHLINKFLAGS. for linking shared objects.
5518, 5523: Delft3D-34148: Enable open boundaries close to partition boundaries5525: DELFT3D-34145: Do not link with libraries when they are not needed5574: DELFT3D-34194: Bug in computation of secondary flow parameter alpha affecting non-equilibrium formulation and effect on momentum equations5584: DELFT3D-34207: Critical erosion shear stress by file and a constant number in sed file gives different results5585: DELFT3D-34149: Remove redundant error message "Deltas > water depth in TRATUR"5586: Restart fluff layer should use fluff layer data and not bodsed data5595: DELFT3D-34153: FLOW+DD+WAVE+nodredging: Computation time increased with a factor 2 with a newer Delft3D version 2b1af7f3a8