Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force use of static library over shared?

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.

like image 665
codehero Avatar asked Jun 07 '10 02:06

codehero


1 Answers

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.

like image 109
BenG Avatar answered Dec 19 '22 01:12

BenG