Page 1 of 1
compile newlib into .so
Posted: Wed Oct 10, 2007 7:46 pm
by mcheung63
Hi
i can only compile newlib in .a , how to compile it in .so (shared lib)?
Which option i need to apply for configure?
thanks
from Peter (
[email protected])
Posted: Wed Oct 10, 2007 11:54 pm
by jnc100
Are you using a toolchain that can produce shared executables? Does libtool work? Do you have a dynamic linker? If so, newlib should build shared libraries anyway. Otherwise, there's always the --enable-shared option.
Regards,
John.
Posted: Thu Oct 11, 2007 9:03 am
by mcheung63
thank you for the response
But i still cannot build a .so from newlib, i searched arround the google, some people said it is not possible to build a shared lib for embedded platform such as arm, but for i386, it should be possible to build a .so
Any other hints?
thanks
from Peter
Posted: Fri Oct 12, 2007 3:27 am
by JamesM
If you're still having problems with it, I could suggest a way to do it... (just thought of it!)
Code: Select all
#!/bin/bash
mkdir tmp
cd tmp
ar x ../libc.a
gcc -G --shared -o libc.so <put flags here> *.o
cp libc.so ../
cd ..
rm -Rf tmp
In a bash script should do it?
Posted: Sun Oct 14, 2007 3:54 am
by jnc100
ELF shared libraries are usually position-independent code whereas static libraries are not - they just have their relocations resolved at link time. They are not only linked differently, but compiled differently in that you need to use a different relocation type (e.g. GOT relative or jump via the PLT) and generally the basic code emitted to call/access data through these relocations is different than what is used in static linking. Therefore, you need to also recompile every source file with the -fpic option too. The libtool script is very handy here.
Newlib does not support shared libraries on many targets, simply because it assumes shared library support not to exist on these targets. 'Support' for a shared library requires far more than just a cross compiler that can emit position-independent code and GOT/PLT relative relocations, you also need a dynamic linker, which is part of the operating system, to fixup all the GOT entries.
As the OP is presumably writing their own operating system (as they're posting to this forum) you still need to be able to answer yes to each of the questions I asked previously to get shared libraries to work. Actually, a dynamic linker isn't that hard, provided you read the
required reading.
Regards,
John.