This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: how to compile the .so to allow extern functions
Done:-), thank Brain for the help!
$ cat bug1.c
//this will be .so and will call an extern func1() in the main proc
int func1();
int myfunc()
{
printf("in myfunc.so\n");
func1();
}
$ cat bug1-main.c
#include <dlfcn.h>
int func1()
{
printf("in main.func1()\n");
return 0;
}
int main()
{
int (*mf)();
void *handle = dlopen("bug1.so", RTLD_LAZY);
if(handle) {
mf = dlsym(handle, "myfunc");
if(mf) mf();
dlclose(handle);
}
return 0;
}
$ gcc -shared -o bug1-main.so bug1-main.c -ldl -Wl,--out-implib=libmain.dll.a
Creating library file: libmain.dll.a
$ gcc -shared -o bug1.so bug1.c -L. -lmain
$ gcc -o bug1-main bug1-main.c -ldl
$ ./bug1-main.exe
in myfunc.so
in main.func1()
Regards,
Andy
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/