Author Topic: OpenWatcom & GCC  (Read 5775 times)

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
OpenWatcom & GCC
« on: December 07, 2016, 04:55:28 pm »
I'm trying to link a GCC built DLL to an OpenWatcom binary and it is failing with unresolved symbols.
Seems it is using the wrong calling convention, the OW binary is expecting foo_ instead of the _foo symbol that is exported.
Anyone know the correct OW CFLAGS to produce the correct calling convention, STDCALL IIRC?

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2092
  • Karma: +159/-0
    • View Profile
Re: OpenWatcom & GCC
« Reply #1 on: December 08, 2016, 03:18:06 am »
Hi Dave,

I'm trying to link a GCC built DLL to an OpenWatcom binary and it is failing with unresolved symbols.
Seems it is using the wrong calling convention, the OW binary is expecting foo_ instead of the _foo symbol that is exported.
Anyone know the correct OW CFLAGS to produce the correct calling convention, STDCALL IIRC?

You might need to rebuild the GCC dll with _System declaration around the functions you want to use within OW....

Cheers,

Paul

Valery Sedletski

  • Sr. Member
  • ****
  • Posts: 368
  • Karma: +2/-0
    • View Profile
Re: OpenWatcom & GCC
« Reply #2 on: December 09, 2016, 11:47:54 pm »
2Dave Yeo: You need to specify the correct GCC function prototype in Watcom source header, with correct calling convention. GCC is mostly using __cdecl and Watcom expects  __watcall by default. So, you need to specify __cdecl explicitly in prototypes.

Greg Pringle

  • Full Member
  • ***
  • Posts: 146
  • Karma: +0/-0
    • View Profile
Re: OpenWatcom & GCC
« Reply #3 on: December 14, 2016, 09:59:24 pm »
A number of years ago I had to use the IBM C++ compiler to access old Microsoft OS/2 C DLLs. The way it had to be done was to load the DLL into memory directly and use a far call to directly call the functions. Somewhere I have the code if needed. The technique works fine. You just need to make sure and remove the DLLs manually after use or you end up with a memory leak.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: OpenWatcom & GCC
« Reply #4 on: January 03, 2017, 08:45:00 am »
I was linking to Cairo and used this patch to make it work,
Code: [Select]
--- cairo.h.orig        2016-06-19 22:41:04.000000000 -0700
+++ cairo.h     2016-12-22 23:22:34.000000000 -0800
@@ -53,9 +53,11 @@
 #ifndef cairo_public
 # if defined (_MSC_VER) && ! defined (CAIRO_WIN32_STATIC_BUILD)
 #  define cairo_public __declspec(dllimport)
+# elif defined (__WATCOMC__) && defined (__OS2__)
+#  define cairo_public __declspec(__cdecl)
 # else
 #  define cairo_public
 # endif
 #endif

 CAIRO_BEGIN_DECLS

And of course create an OMF import lib
« Last Edit: January 03, 2017, 08:48:34 am by Dave Yeo »