views:

37

answers:

3

How can I tell the linker that statically link libfoo.a while building the shared object sharedobj.so using gcc/make.

I have tried to pass the LDFLAG options LDFLAGS += -W1 --whole-archive -L/path/to/libfoo -lfoo

I have also tried to pass LDFLAGS the options LDFLAGS += -W1, static -L/path/to/libfoo -lfoo

I have also tried to pass LDFLAGS the options LDFLAGS += -W1, Bstatic -L/path/to/libfoo -lfoo

and

I have also tried to pass LDFLAGS the options LDFLAGS += -W1, statically_linked -L/path/to/libfoo -lfoo

I have read through a number of links that tell me how to do it but none have worked so far.

+1  A: 

LDFLAGS is just a feature of auto(conf|crap), and linker never looks at it. Just give all options on the command-line, like:

gcc obj1.o obj2.o ... -shared -o libfoo.so -L/path/to/lib -lbar

zvrba
A: 

I do not really understand, do you want the static library be part of your shared one?

Then it should work when you add it as a dependency - like the other object (.o) files.

Link a.o b.o c.o staticlib.a into libsharedobj.so

nob
Yes. This is exactly what I want to do.
Swaroop S
A: 

You might think of an library as an archive (.a) of object (.o) files. You can use it in a similar way to object files in your linker step.

It's unclear to me however if all of the archive will be included in the shared object library (or exe) or only those parts required - my understanding was only what is required but I haven't played with *nix for a bit. For a .so that might mean it won't include and export anything that isn't used by the .so itself.

Greg Domjan