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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
SpideyMod
Community Support Moderator @Experts Exchange
of .o from it, you can simply use
% ld -shared -o mydynlib.so -Lmystaticlibname
Assume your static library name is libmystaticlibname.a
kejin