tags:

views:

165

answers:

2

Hi, In my SConscript I have the following line:

Program("xtest", Split("main.cpp"), LIBS="mylib fltk Xft Xinerama Xext X11 m")

How do I get scons to use mylib.a instead of mylib.so, while linking dynamically with the other libraries?

EDIT: Looking to use as few platform specific hacks as possible.

+2  A: 
daramarak
I don't think any of those variables apply in this situation. The linker is actually doing the selection between the static vs. dynamic libraries when it finds both on disk. The pre/suffixes you mention only change the filename patterns of targets declared in scons.
BennyG
env[SHLIBSUFFIX] returns as string containing the file suffix of the platform you are after. It would be a nice idea to test the answers this before actually downvoting.
daramarak
I have removed my downvote with your new edit.
BennyG
+2  A: 

Passing the full filepath wrapped in a File node will force static linking. For example:

lib = File('/usr/lib/libfoo.a')
Program('bar', 'main.c', LIBS = [lib])

Will produce the following linker command line

g++ -o bar main.o /usr/lib/libfoo.a

Notice how the "-l" flag is not passed to the linker for this LIBS entry. This effectively forces static linking. The alternative is to modify LINKFLAGS to get what you want with the caveat that you are bypassing the library dependency scanner -- the status of the library will not be checked for rebuilds.

BennyG
I have verified that the solution works. However, I will note that my solution resembles more:SConscript:...lib = File(env.MyLibFile)and in the SConstruct:env.MyLibFile = "/usr/lib/libfoo.a")So that my windows SConstruct can override the filename.
codehero
This is not platform independent. To achieve that use the SHLIB suffix as noted in my answer. Like File('libfoo'+env['SHLIBSUFFIX'])
daramarak
Yes, good point about the use of platform-independent variables for prefix and suffix.
BennyG