-
-
Notifications
You must be signed in to change notification settings - Fork 330
StaticallyLink
garyo edited this page Dec 13, 2014
·
2 revisions
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:
#!python
env=Environment();
static=env.Command('libstdc++.a',None,Action('ln -s `g++ -print-file-name=libstdc++.a` $TARGET'));
lib=env.StaticLibrary(target='mylib',source='mylib.cpp',LIBPATH='.',LINKFLAGS='-static-libgcc',LIBS=[static]);
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:
#!python
env = Environment(
# LINKCOM needs to be specifed here because of the special handling when
# linking against the static libgcc and stdc++
LINKCOM = "$LINK -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $LINKFLAGS",
LINKFLAGS = "-static-libgcc -ldl -Xlinker -B -Xlinker static -lstdc++")
prog = env.Program(target='myprog',source='main.cpp');