I'm trying to build a shared library in Cygwin using an i686-elf cross-compiler. The code is very simple:
int add(int a, int b) {
return a + b;
}
void _init() {
add(3, 4);
}
I'm compiling with the following command:
i686-elf-gcc -fPIC -shared -nostdlib core.c -o libcore.so
This should be producing a shared object, right? But GCC outputs a warning about not being able to find the _start
symbol, which is the entry point for executables, not shared objects. Furthermore, readelf
says the following:
$ readelf -a libcore.so
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
...
Type: EXEC (Executable file)
...
What's going wrong here?
What's going wrong is essentially that you're targeting i686-elf, and nobody builds shared libraries for that target. -Wl,-shared
will give you something which is marked as a shared library, but how exactly do you plan to load a shared library on a bare-metal target?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With