Re: [Mingw-users] undefined reference to _imp__*
-----BEGIN PGP SIGNED MESSAGE-----
On 18/01/17 20:32, Cervinka, Mitch wrote:
> I am new at MinGW and was not aware that DLLTOOL is no longer
You are reading too much into Earnie's statement; often, you may
not need an import library, since current versions of the linker support direct linking to DLLs, but dlltool _is_ still supported;
indeed, we still use it when building mingwrt and w32api.
> I had originally tried linking directly without the import library,
> but was getting "undefined reference" messages because the MinGW
> linker was expecting the prefix "_imp__" in front of all the imported
> symbol names, but the symbols in the DLL do not have this prefix.
Yes, they do ... implicitly; you just will not normally see them
on examination of the DLL itself, but you can see them in any
import library you generate from your DLL.
> The DLL exports its symbols using the STDCALL convention, so I assume
> I need to import them using STDCALL. I wasn't seeing these linker
> errors when I tried to import using CDECL, but I was getting
> exceptions when I tried to run the code. I don't believe it is valid
> to import symbols using CDECL if the DLL was exported with STDCALL,
> is it?
No, it isn't. STDCALL pops arguments off the stack _before_ the
function returns; CDECL leaves the caller to pop them _after_ the
function returns. Specifying this inappropriately trashes the
stack, and likely will induce crashes.
> I do not have the luxury of rebuilding the DLL I am trying to import,
> so I am stuck with using STDCALL. I believe life would be much
> easier if we were using CDECL, but that is not an option for me.
STDCALL functions normally append an @N decoration to the symbol
name, (with no intervening space ... the @N references in your DEF
file are entirely different ordinal references), but some DLLs do
not export them in this fully qualified form. If you have one of
these, you may need to build an import library in which you
specify both the qualified and unqualified forms; (the N in the
required "Symbol@N" references represents the number of bytes in
the argument list, which the associated function will pop off the
stack when it returns).
Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)
-----END PGP SIGNATURE-----
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
MinGW-users mailing list
This list observes the Etiquette found at
We ask that you be polite and do the same. Disregard for the list etiquette may cause your account to be moderated.
You may change your MinGW Account Options or unsubscribe at: