Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

How to statically link the c++ runtime libraries (and statically link libgcc) in a sconsy way:

As of scons 2.0.1 adding LINKFLAGS="--static" to Program() seems to work on Ubuntu 10.4.

Example:

Program("test.cxx",
                                LIBS=["boost_unit_test_framework"],
        LIBPAH = ["/usr/lib", "/usr/local/lib"],
        LINKFLAGS="--static")

Previous methods are:

   1 env=Environment();
   2 static=env.Command('libstdc++.a',None,Action('ln -s `g++ -print-file-name=libstdc++.a` $TARGET'));
   3 lib=env.StaticLibrary(target='mylib',source='mylib.cpp',LIBPATH='.',LINKFLAGS='-static-libgcc',LIBS=[static]);
   4 prog=env.Program(target='myprog',source='main.cpp',LIBS=[static,lib],LINKFLAGS='-static-libgcc',LIBPATH='.');

Warning: the first recipe wont work with scons 0.96.1 or lower.

How to statically link on Solaris 5.8, GCC 3.2 and SCons 0.96.1:

   1 env = Environment(
   2     # LINKCOM needs to be specifed here because of the special handling when
   3     # linking against the static libgcc and stdc++
   4     LINKCOM = "$LINK -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $LINKFLAGS",
   5 
   6     LINKFLAGS = "-static-libgcc -ldl -Xlinker -B -Xlinker static -lstdc++")
   7 
   8 prog = env.Program(target='myprog',source='main.cpp');

StaticallyLink (last edited 2013-08-28 20:44:31 by WilliamDeegan)