tags:

views:

643

answers:

4

I'm trying to get SCons to make a shared library. One of the items going into the .so is a .a static lib.

I have a line like: env_2.SharedLibrary('libstuff.so', Split("""stuff.cxx mylib/libMine.a""")

And upon running get an error: scons: * Source file: mylib/libMine.a is static and is not compatible with shared target: libstuff.so

However, I know that a shared library can be made from the .a via command like.

g++ -m32 -shared -o libstuff.so stuff.o mylib/libMine.a

Any ideas on getting this to work are doing the run around the issue would be greatly appreciated.

-jk


Related question is how do I get scons to put an additional string "-shared" on the LINK command line for the Program() call. If I could do this, I think it would meet my needs.

+1  A: 

This problem is not specific to scons. To build a shared library, you'll need objects that are compiled with position independent code (-fPIC). Your best bet is to make the shared library out of the source files compiled with the right options.

In SCons, you can define a list of targets that's used to build both libMine.a and libShared.so.


Update: for your second question, the SharedLibrary builder might do what you need:

SharedLibrary('foo', ['f1.c', 'f2.c', 'f3.c'])

If not, LINKFLAGS sets the flags passed to a link command.

Dave Bacher
I think you are right that the .a has .o files NOT made using -fPIC. However the g++ -m32 -shared .... still works somehow.
xavjuan
I went back and had the files going into the .a be compiled with -fPIC, but that didn't seem to help.
xavjuan
The LINKFLAGS was helpful. thx.
xavjuan
A: 

env_2.SharedLibrary('libstuff.so', Split("""stuff.cxx"""), LIBS='libMine.a', LIBPATH='mylib')

This should work.

dummytaurus
A: 

I've the same problem under cygwin. I passed '-fPIC' options to gcc when building the objects and got the following warning:

warning: -fPIC ignored for target (all code is position independent)

I also passed '-shared' to the link command. And I finally got the error

"*.lib is static and is not compatible with shared target: myso.dll"

It seems scons doesn't allow to create so directly from obj or lib files, and one can either create the so from a list of sources files (using SharedLibrary()) or source file + 'LIBS' option like dummytaurus says. I'm curious about that.

NovelX