Dynamic loading of cygwin dependent dlls
Peter Ekberg
peda@axentia.se
Tue Aug 10 19:49:00 GMT 2004
Christopher Faylor wrote:
>On Thu, Aug 05, 2004 at 09:09:40AM +0200, Peter Ekberg wrote:
>>I have read several messages stating that dlopen does not work for
dlls
>>that depend on cygwin1.dll.
>>(e.g. http://sources.redhat.com/ml/cygwin/2004-06/msg01056.html).
>>I have also understood that this is due to some structures not being
>>initialized in that case.
>>
>>Is this dlopen problem limited to non-cygwin apps? I.e. is it true
>>that an app that depends directly on the cygwin1.dll is incapable of
>>dlopening dlls that depend on cygwin1.dll?
>
>No, it is not true. dlopen would be pretty worthless if it didn't work
>in a standard cygwin program.
Indeed. Knowing that it should work, I was inspired to do some more
tests.
The reason I asked is that the following results in a dll that can't be
dlopened:
foo.c:
------------8<---------------
__declspec(dllexport) int foo(int bar);
int foo(int bar)
{
return bar;
}
------------8<---------------
Build commands:
$ gcc -c foo.c
$ dlltool --dllname pseudo_stubs.dll --exclude-symbols
DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12,DllMainCR
TStartup@12,DllEntryPoint@12 --output-def foo.def foo.o
$ dllwrap --dllname pseudo_stubs.dll --output-lib pseudo_stubs.dll.a
--def foo.def foo.o -L/usr/lib
However, further tests have shown that if I change the name pseudo_stubs
to foo in the above commands, it works like a charm. Like this:
$ gcc -c foo.c
$ dlltool --dllname foo.dll --exclude-symbols
DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12,DllMainCR
TStartup@12,DllEntryPoint@12 --output-def foo.def foo.o
$ dllwrap --dllname foo.dll --output-lib foo.dll.a --def foo.def foo.o
-L/usr/lib
I use this program to test whether the resulting dll works:
load.c
------------8<---------------
#include <stdio.h>
#include <dlfcn.h>
char *dlls[] = {
"pseudo_stubs.dll",
"foo.dll",
NULL
};
int main(void)
{
int i;
void *res;
for(i=0; dlls[i]; ++i) {
printf("%s\t", dlls[i]);
res=dlopen(dlls[i], RTLD_LAZY | RTLD_GLOBAL);
if(!res)
printf("%s\n", dlerror());
else
printf("ok\n");
}
return 0;
}
------------8<---------------
I build load.c with "gcc load.c -o load" and ./load produces this
output:
pseudo_stubs.dll dlopen: Win32 error 998
foo.dll ok
Any help on this would be appreciated.
Cheers,
Peter Ekberg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 28008 bytes
Desc: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20040810/5beaf258/attachment.obj>
-------------- next part --------------
--
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/
More information about the Cygwin
mailing list