Link to home
Start Free TrialLog in
Avatar of s_narayan
s_narayan

asked on

how to link static library to a shared library

Hello,
        I am trying to build a shared library. This library in turn makes a call to static library provided by the Operating system. Please let me know how do i link this static library to the shared library.
Finally this shared library has to be linked to an executable.

Best regards
Narayan
ASKER CERTIFIED SOLUTION
Avatar of kejin
kejin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kejin
kejin

Also, if you only need to link static library into the shared library, you don't need to extract all
of .o from it, you can simply use

   % ld -shared -o mydynlib.so -Lmystaticlibname

Assume your static library name is libmystaticlibname.a

kejin
That -L should be -l, and you also need to include the main object files in the link!  E.g.

ld -shared -o mydynlib.so -lmystaticlibname dynlib1.o dynlib2.o ...

And I would use gcc instead of ld as the linker.  Gcc uses ld for its linking, but is usually configured to add necessary search paths and other options to the ld invocation.

And the code in the static library doesn't have to be position independent (i.e. compiled with gcc -fpic).  If it isn't, the shared library won't be as shared as you might like, though.  It will contain more copy-on-write areas.
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange