I create a .so
file with the code below, but when I compile a file that invokes functions in the .so
file with GCC, I get an "undefined reference to 'outlib1'" error.
What's wrong with my code or my command? Thanks.
OS Ubuntu 11.10
gcc 4.6.1
//file name outscreen.c
#include <stdio.h>
void outlib1(void)
{
printf("out screen func1\n");
}
//file name main.c
int main(int argc, char* argv[])
{
outlib1();
}
gcc outscreen.c -fPIC -shared -o outscreen.so
gcc main.c -L. -loutscreen -o call
./call
Try:
$ gcc outscreen.c -fPIC -shared -o liboutscreen.so
$ gcc main.c -L. -loutscreen -o call
(note the change to the first line - the second line is unchanged)
What is the output of this?
nm outscreen.so | grep outlib1
Perhaps it is exporting with an underscore.
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