linking dilemma (undefined reference) between MinGW and MSVC. MinGW fails MSVC works

后端 未结 2 336
后悔当初
后悔当初 2020-12-21 13:47

I\'m trying to port an old C .dll library originally done with MSVC that uses BEA Tuxedo library to use MinGW.

I have encountered a situation where MSVC compiles an

相关标签:
2条回答
  • 2020-12-21 14:04

    As you have already discovered yourself - name mangling may be different across compilers. To solve your problem follow the instructions:

    1. Download and install (can build from source) gendef utility:

      • If you have usual MinGW (targeting 32-bit), then obtain it here;
      • If you have MinGW-w64 (targeting 64-bit), then obtain it here.
    2. Run gendef wtuxws32.dll (will generate wtuxws32.def);

    3. Run dlltool -D wtuxws32.dll -d wtuxws32.def -l libwtuxws32.a (will generate libwtuxws32.a);

    4. Put libwtuxws32.a to D:/dev/tuxedo/lib;

    5. Now link against it.

    0 讨论(0)
  • 2020-12-21 14:18

    Change the declaration of tpsetunsol() in the atmi.h header from:

    extern void (_TMDLLENTRY * _TMDLLENTRY tpsetunsol _((void (_TMDLLENTRY *)(char _TM_FAR *, long, long)))) _((char _TM_FAR *, long, long));
    

    to:

    extern  void (_TMDLLENTRY * (_TMDLLENTRY tpsetunsol) _((void (_TMDLLENTRY *)(char _TM_FAR *, long, long)))) _((char _TM_FAR *, long, long));
    //                          ^                      ^
    

    so the function will be properly declared to be a stdcall function as it is in the library (as indicated by the @4 suffix on the name in the library).

    0 讨论(0)
提交回复
热议问题