I would like to figure out how to build a shared library which can then
be used by some of my applications. As an instructive project, I’m doing
the following:
- Create a shared library, libShared.so that has a single function:
// Shared.c
void
Foo()
{
printf(“In the shared library!\n”);
}
- Create a program, which just calls into the shared library:
// Main.c
int
main()
{
printf(“Before foo\n”);
Foo();
printf(“After foo\n”);
return 1;
}
I can’t seem to get this to work. I build everything as follows:
Build the shared library
qcc -o Shared.o Shared.c
qcc -shared -o libShared.so Shared.o
Build the app, using the shared library
qcc -o Main.o Main.c
qcc -o Test Main.o libShared.so
When I run Test, I get a core dump. gdb is singularly uninformative –
I’m guessing that is dying way early in startup.
Can someone give me a push in the right direction. I’d really like to
get shared libraries working in my project.
Thanks in advance,
Eric