OT: Linux shared lib question
Bill Baxter
dnewsgroup at billbaxter.com
Mon May 12 16:57:05 PDT 2008
Not really a D question, but I'm hoping someone out there knows the
answer (it is for the purpose of getting my D Multiarray library working
better on Linux, though.)
I want to create a shared .so from a .a library.
I found on a web page somewhere that a .so can be created from some .o
files using something like the following:
gcc -shared -Wl,-soname,lib${name}.so.1 -o lib${name}.so.1.1 \
a.o b.o c.o
So I figured if it can do that then surely this would work:
gcc -shared -Wl,-soname,lib${name}.so.1 -o lib${name}.so.1.1 \
libmylibrary.a
where libmylibrary.a is a lib containing a.o, b.o, and c.o. After all a
.a archive is basically just a concatenation of .o files in a convenient
package.
However, though the command runs without reporting an error, the
resulting .so does not contain the contents of libmylibrary.a.
SO what I'm doing now in my "make .so from .a" script is basically this:
mkdir tmp
cd tmp
ar x path/to/libmylibrary.a
gcc -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.1 *.o
rm *.o
cd ..
rmdir tmp
Extract the .o's from the .a, make the shared lib using that, then clean
up.
Is that really the best way to do this? With MinGW you can directly
create a dll from a .a, so I was a bit surprised to find out that the
same gcc flags do not work on Linux to create a .so. Is this a case
where the Windows version of a GNU tool is actually easier to use than
the Linux version?
--bb
More information about the Digitalmars-d-learn
mailing list