问题
I know how to create shared libraries using gcc
and ln
, but how do I create a shared library using only ld
when I have object files (from c++ or c code) as input and how do I swap onto new version of library?
回答1:
how do I create a shared library using only ld when I have object files (from c++ or c code) as input
You could run gcc -v -shared ...
to discover what options gcc
passes to ld
. You could then pass the same arguments to ld
directly, and you should end up with identical result.
Note: this is ill-advised (don't do this): the arguments change with different versions of gcc
and ld
, and they change from one OS release to the next.
It is very common to construct link lines for ld
that used to be correct some years ago, but no longer are. The bugs introduced when doing this are often low-level and subtle, and beyond most programmers' ability to understand and fix.
来源:https://stackoverflow.com/questions/36876689/how-do-i-create-shared-library-using-ld