Web lists-archives.com

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




I've been working more on trying to get this going. I tried adding non-annotated aliases to the def file myself both ways, so:
ncdActivateChannel          @23
...
ncdActivateChannel@8 = ncdActivateChannel
...


as well as
ncdActivateChannel@8        @23
...
ncdActivateChannel = ncdActivateChannel@8
...


and in both cases it links but has the same entry point error.


I also looked at the vcand32.dll file in MS's Dependency Walker and it shows all the exported functions without @XX annotations. Does this indicate that for the DLL expected calling convention is __cdecl instead of __stdcall or is it not conclusive?



The header checks for the macro __cplusplus and wraps everything in extern "C" {} if it's present (it is). Then:
#if (__FLAT__) || defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
 #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__)
  #define _EXPORT_API     __stdcall
 #else
  #define _EXPORT_API
 #endif
#else
 #define _EXPORT_API       _far _pascal
#endif

#ifndef DYNAMIC_CANDRIVER_DLL
 // not used for dynamic load of dll
 #define _EXPORT_DECL  __declspec(dllimport) _EXPORT_API
 #define _EXPORT_DEF  __declspec(dllimport) _EXPORT_API
#endif


Where _WIN32 was already defined, I define _STDCALL_SUPPORTED before including the header, and DYNAMIC_CANDRIVER_DLL is not defined.


On Wed, Feb 24, 2016 at 9:40 AM, Chris <chricro@xxxxxxxxx> wrote:
By the way, when I said "The result is the same" I meant the result of `nm libvcand32.dll.a | grep ncdActivateChannel`.

On Wed, Feb 24, 2016 at 9:39 AM, Chris <chricro@xxxxxxxxx> wrote:
John,

Thanks for the prompt and detailed response.

I was able to set all of the calling conventions to __stdcall. Then I was able to link the .dll.a that I build with dlltool using the MSVC def file (with @XX in it). However, at runtime my program closes with a Windows pop-up dialog saying: "The procedure entry point ncdActivateChannel@8 could not be located in the dynamic link library vcand32.dll".

Why am I supposed --add-stdcall-alias in dlltool's options when the def already contains @XX for every symbol? Whether I include it or not, the result is the same:

00000000 I __imp__ncdActivateChannel@8
00000000 T _ncdActivateChannel@8

In fact, this is the case whether I use any of the following:
$ dlltool --input-def vcandm32.def --dllname vcand32.dll --output-lib libvcand32.dll.a
$ dlltool --input-def vcandm32.def --dllname vcand32.dll --output-lib libvcand32.dll.a --kill-at
$ dlltool --input-def vcandm32.def --dllname vcand32.dll --output-lib libvcand32.dll.a --add-stdcall-alias


At least in the --kill-at version I would have expected to see _ncdActivateChannel without @8.

While editing the header I noticed that every function also has __declspec(dllimport) before __stdcall as well, if that changes things.

Chris




On Wed, Feb 24, 2016 at 6:41 AM, John Brown <johnbrown105@xxxxxxxxxxx> wrote:
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
like:
#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
*/
...
#else
/* Unknown compiler - you tell me how to indicate __stdcall */
int ncdActivateChannel(type1 arg1, type2 arg2);
#endif

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.

Regards,
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!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
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:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe



------------------------------------------------------------------------------
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!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
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:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe