Mingw seems to be unable to export functions which are
contained in a library (.a file). I do not know whether
it is a bug or expected behaviour though.
--- dllmain.c ---
#include <windows.h>
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD
dwReason, void *lpReserved)
{
return TRUE;
}
--- testdll.c ---
void fn()
{
}
--- testdll.def ---
LIBRARY testdll.dll
EXPORTS
fn PRIVATE
----------------
compiles fine:
gcc -c testdll.c
gcc -o testdll.dll -mdll dllmain.c testdll.o testdll.def
fails (writes: Cannot export fn: symbol not defined):
gcc -c testdll.c
ar cru testdll.a testdll.o
gcc -o testdll.dll -mdll dllmain.c testdll.a testdll.def
Source files are attached for your convenience.
Logged In: YES
user_id=11494
Put the .def file before the libarary that contains the
definitions, otherwise ld will not look for the .def'd symbols in
the library eg:
gcc -o testdll_fail.dll -mdll testdll.def dllmain.c testdll.a
As a general rule, the def file should come first in the list of
objects/libaries.
Also, it is probably better to use -shared rather tha -mdll.
With older binutils, -mdll does not do the same thing as -
shared, but produces a non-relocatable dll. With current ld -
mdll and -shared do the same thing, but I think that is abug
that needs to be fixed.
Danny
Logged In: YES
user_id=15438
I thought -mdll was deprecated and was supposed to be
exactly the same as -shared.
Earnie.
Logged In: YES
user_id=541569
Thanks for the explanation about .def file.
It seems to me that I had not only this problem but a
combination of two problems. The first one is just improper
location of .def file in a command line, is is clear now.
Now here is the second:
looks like -Wl,--enable-stdcall-fixup switch does not affect
object files from libraries. In my real program I tried to
export stdcall functions.
Here is another testcase attached which shows this.
I know how workaround this (place fn=fn@0 PRIVATE in a .def
file). But I think that this information might be
interesting for you.
The combination of these two problems appeared to be too
difficult for me to solve. Thanks again for your fast and
informative reply, it really helped a lot.
Logged In: YES
user_id=11494
The function --enable-stdcall-fixup switch is to fixup linkages
needed to resolve undefined references when linking objects
into an executable (exe or dll). ie.if linker can't find foo@nn
but can find foo, it fixes up the stdcall symbol to the
undecorated symbol ( and converserly if it needs foo but can
only find foo@nn). This is for both static and dynamic linkage.
It really was intended to do what you are asking it to do.
What I would do in your case is to change the def file to:
LIBRARY testdll.dll
EXPORTS
fn@0 PRIVATE
and use the --add-stdcall-alias switch
gcc -o testdll.dll -Wl,--add-stdcall-alias -shared testdll.def
dllmain.c testdll.a
This will create a dll that exports fn@0 and the alias foo, so it
can be used by both C clients and VB clients with minimum
fuss.
Or you could explicitly do the alias as you indicate.
This type of discussion should go to mingw-users list, so I'll
close this bug report again. No criticism intended.
Danny