[Mono-osx] [Mono-list] interacting with external libraries
Jonathan Pryor
jonpryor at vt.edu
Tue Mar 27 06:51:31 EDT 2007
On Fri, 2007-03-23 at 18:19 +0100, Svetoslav Marinov wrote:
> Is there a way to convert an ".a" library into ".so" one? In case I
> cannot use the libTimbl.a directly.
No. First, there's the file format issue -- .a files are generated by
ar(1) and cannot be loaded by ld.so(8), while .so files are generated by
the compiler and are (1) executable (`/lib/libc.so.6` is a valid
command), and (2) can be loaded by ld.so(8) and dlopen(3). Neither of
these attributes is true for .a files.
So you cannot use .a files from [DllImport] methods, only .so files.
You can turn a .a file into a .so file though, by e.g.:
gcc -shared -o libfoo.so libfoo.a
But then we get to the other problem: .so files need to be linked
from .o files which have -fpic specified, so they contain
position-independent code (this allows the .so to be located anywhere in
memory, with no fixed addresses -- required for shared libraries). .a
files are (typically) linked from .o files which do NOT have -fpic
specified.
If you know that your .a file contains -fpic compiled code (or you're on
a platform where all code is position-independent -- the gcc man page
lists RS/6000 is one such platform), this will work, but in all
likelihood it will NOT, in which case the only thing you can do is
rebuild the entire library, ensuring that -fpic is specified when
creating each .o file.
- Jon
More information about the Mono-osx
mailing list