Web lists-archives.com

Re: [Mingw-users] Problems creating linkable file from MSVC .lib

Chris <chricro@...> writes:

> I found out a little bit more:
> ... there was a set of .lib and .def files for each of MSVC and
> Borland C. The only difference I could make out in the def files
> was that the MSVC one has  <at> XX after each symbol, while the
> Borland one does not. So:    
> ncdActivateChannel              @23 // Borland
> vs
> ncdActivateChannel@8            a@23  //MSVC
>  Running dlltool using  the borland .def file gave me a .dll.a
>cthat I can link against (although I'm not sure why running it on
> the MSVC one with the -k option wouldn't, then?).

If you the `add-stdcall-alias' flag to your dlltool command line, you
will create a DLL that exports 2 names for each function:
ncdActivateChannel@8 *and* ncdActivateChannel. This latter name
(from the Borland .def file) seems to be the name that the linker
is looking for. You will probably still experience the same problems
that you describe below.

> However I've run into trouble, whether I link against the dll.a
> that I created from that .def or just straight against the
> vcand32.dll: I'm having some issues with memory corruption when
> I call functions from this library that I don't have anywhere
> else. So, sometimes (but not always) my program will crash with a
> SIGSEGV when I call certain functions from this library.

As I said in my last email, I believe that that you have a mismatch
in calling conventions. That is, the compiler is generating code in
your .o files to call c functions, but the functions are actually
stdcall functions, or vice versa. This is how I would find out what
is happening.

1) Locate the declaration of ncdActivateChannel and determine the
calling convention (which is C by default). You might see something
#if defined(_MSC_VER)
int __stdcall ncdActivateChannel(type1 arg1, type2 arg2);
#elif defined(__BORLANDC__)
/* Borland stdcall function declaration goes here. I don't
   remember how they do it
/* Unknown compiler - you tell me how to indicate __stdcall */
int ncdActivateChannel(type1 arg1, type2 arg2);

Note that it is possible that no #if matches __MINGW32__, in which
case the default declaration is the one that would be selected
when you compile with MinGW.

If it turns out that your functions are not marked as stdcall, you
will have to modify the header. If the _MSC_VER branch is OK, you
might get away with 
#if defined (_MSC_VER) || defined (__MINGW32__)
int __stdcall ncdActivateChannel(type1 arg1, type2 arg2);
int __stdcall ncdBlahBlahBlah(...
wherever you see #if defined(_MSC_VER).

Another option may be to add the -mrtd switch (which changes the
default calling convention) to your gcc command line *instead of*
modifying the function declarations.

After you have fixed the header, build the import library using the
MSVC .def (with @n suffixes) and include --add-stdcall-alias in the
dlltool command line.

John Brown.
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
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:
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe