Repository navigation
Description
This issue was originally created at: 2011-03-21 09:50:40.
This issue was reported by: axeoth.
axeoth said at 2011-03-21 09:50:40
Dear SCons team,
I ask you to implement the following: when in the same folder there are both static and shared versions of some library (let's say libfoo.a and libfoo.so), to be able to force using the static or the shared one, someting along these lines:
# Link foo statically, bar dynamically
gcc -Bstatic -lfoo -Bshared -lbar foobar.o -o foobar
You find below a possible solution that involves a bit of hacking:
http://old.nabble.com/Static-library-linking-td26582198.html (see the last message on that page, also copied below)
It should be nice to have that solution integrated into the standard SCons.
The feature is quite asked for, as you may find through the following links:
Many Thanks!!!!
=============SOLUTION==========================
Re: Static library linking
by Ringo De Smet Sep 15, 2010; 04:39pm :: Rate this Message: - Use ratings to moderate (?)
Jean-Baptiste,
On 15 September 2010 13:52, Jean-Baptiste Lab
Just been playing with that myself and have currently settled for the non-portable following:
boost_utf_lib = env.File('/usr/lib/libboost_unit_test_framework.a')
env.Append(LIBS=boost_utf_lib) But I'd like to have something less hack-ish.
What I got so far, the SCons way...
Put the lines between the markers in the file
site_scons/site_tools/StaticLink.py:
def generate(env, **kwargs):
# Only supported when using GCC
if env['CC'] == 'gcc':
env['STATICLIBS'] = []
env['SHAREDLIBS'] = []
env['_STATICLIBFLAGS'] = '${_stripixes(LIBLINKPREFIX, STATICLIBS, LIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}'
env['_DYNAMICLIBFLAGS'] = '${_stripixes(LIBLINKPREFIX, SHAREDLIBS, LIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}'
env['_LIBFLAGS'] = '-Wl,-Bstatic ${_STATICLIBFLAGS} -Wl,-Bdynamic ${_DYNAMICLIBFLAGS}'
print env.Dump()
def exists(env):
# Only supported when using GCC
if env['CC'] == 'gcc':
return True
return False In your SConstruct, just after the construction of your Environment, but before the rest of your build definition:
env.Tool('StaticLink')
env.Append(STATICLIBS = 'gtest_main')
env.Append(SHAREDLIBS = 'pthread') This did it for me so far. I am now looking into writing specific Configure checks that will append the lib to the correct list if the library can be found, for example:
conf = Configure(env)
conf.CheckStaticLib('gtest', language='C++') Will post the results when I have more...
Ringo
Activity
mwichmann commentedon Oct 30, 2023
The problem of SCons not being able to keep linker instruction flags together with libraries they may relate to remains. However, the GNU linker syntax (
-l:filespec) for not modifyingfilespecis supported since #4429, in addition to theFile()methods described here; both are documented in the manpage entry for$LIBS. Closing this one.