Compiling Notes

These are some set of light notes I took while trying to compile some old PM samples on 2023. My goal was to see how some PM samples can be compiled with open source tools like gcc, wrc, wl and make.

RPM Packages
I always confuse the RPM packages that I use to compile things with GCC. I want to use as much as open source tools available. Here it is what I install:
 * yum install git gcc make libc-devel binutils
 * watcom-wrc
 * watcom-wlink-hll

Checking the Environments
Execute %INCLUDE% and see if something shows up.

CHAR * {aka char *}
gcc -Wall -Zomf -c -O2 bitcat2.c -o bitcat2.obj bitcat2.c: In function 'main': bitcat2.c:36:29: warning: pointer targets in passing argument 2 of 'WinRegisterClass' differ in signedness [-Wpointer-sign] 36 |      WinRegisterClass(hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0); |                                  |                             |      |                             CHAR * {aka char *} In file included from W:/usr/include/os2.h:39, from bitcat2.c:4: W:/usr/include/os2emx.h:6138:47: note: expected 'PCSZ' {aka 'const unsigned char *'} but argument is of type 'CHAR *' {aka 'char *'} I replaced static CHAR szClientClass[] = "BitCat2"; for unsigned char    szClientClass[] = "BitCat2"; and warnings were removed.
 * Warning
 * Fix

'WinCreateStdWindow' makes integer from pointer without a cast [-Wint-conversion]
vectfont.c:33:38: warning: passing argument 7 of 'WinCreateStdWindow' makes integer from pointer without a cast [-Wint-conversion] 33 |                                     NULL, ID_RESOURCE, &hwndClient) ;      |                                      ^      |                                      |      |                                      void * I replaced the NULL by 0
 * Fix

weakld: error: Unresolved symbol (UNDEF) '_max' '_min'

 * Error

 weakld: error: Unresolved symbol (UNDEF) '_max'. weakld: info: The symbol is referenced by: C:\dev\DEV-SAMPLES-PM-VectFont\vf00.obj C:\dev\DEV-SAMPLES-PM-VectFont\vf14.obj weakld: error: Unresolved symbol (UNDEF) '_min'. weakld: info: The symbol is referenced by: C:\dev\DEV-SAMPLES-PM-VectFont\vf00.obj C:\dev\DEV-SAMPLES-PM-VectFont\vf05.obj C:\dev\DEV-SAMPLES-PM-VectFont\vf14.obj Ignoring unresolved externals reported from weak prelinker. Warning! W1058: file ldgVmPcu.: line(35): protmode option not valid for an OS/2 EMX executable Error! E2028: _max is an undefined reference Error! E2028: _min is an undefined reference file C:\dev\DEV-SAMPLES-PM-VectFont\vf00.obj(vf00.obj): undefined symbol _max file C:\dev\DEV-SAMPLES-PM-VectFont\vf00.obj(vf00.obj): undefined symbol _min 

Include to the .H file the following missing:  
 * Fix
 * 1) ifndef max
 * 2) define max(a,b) (((a) > (b)) ? (a) : (b))
 * 3) endif
 * 4) ifndef min
 * 5) define min(a,b) (((a) < (b)) ? (a) : (b))
 * 6) endif

weakld: error: Unresolved symbol (UNDEF)

 * Error

 weakld: error: Unresolved symbol (UNDEF) 

Removed this from .def  EXPORTS OBJECTWINPROC CLIENTWINPROC 
 * Fix

weakld: error: Unresolved symbol (UNDEF) '_CSPCSTA4'.
 weakld: error: Unresolved symbol (UNDEF) '_CSPCSTA4'. file C:\dev\5TRYING\UTIL-FILE-NewFileManager\nfm.obj(nfm.c): undefined symbol _CSPCSTA4 
 * Error

Need a leading underscore in the export in cspcsta4.def,  EXPORTS     _CSPCSTA4 @1 
 * Fix

'WinSendMsg' makes pointer from integer without a cast
 vectfont.c:36:18: warning: passing argument 3 of 'WinSendMsg' makes pointer from integer without a cast [-Wint-conversion] 36 |                 WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE), |                 ^      |                  |      |                  HPOINTER {aka long unsigned int} In file included from C:/usr/include/os2.h:39, from vectfont.c:7: C:/usr/include/os2emx.h:5819:59: note: expected 'MPARAM' {aka 'void *'} but argument is of type 'HPOINTER' {aka 'long unsigned int'} 5819 | MRESULT APIENTRY WinSendMsg (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2); |                                                   ~^ 
 * Warning

Changed:  WinSendMsg (hwndFrame, WM_SETICON,                WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),                 NULL) ;  To:  WinSendMsg (hwndFrame, WM_SETICON,                (MPARAM) WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, (BOOL) FALSE),                 NULL) ; </PRE>
 * Fix

warning: pointer targets in passing argument 4 of 'GpiCharStringAt' differ in signedness
 vf01.c: In function 'Display_24Point': vf01.c:44:38: warning: pointer targets in passing argument 4 of 'GpiCharStringAt' differ in signedness [-Wpointer-sign] 44 |                           szFacename[iFont]) ;      |                            ~^      |                                      |      |                                      CHAR * {aka char *} In file included from C:/usr/include/os2.h:39,                 from vf01.c:6: C:/usr/include/os2emx.h:9050:11: note: expected 'PCCH' {aka 'const unsigned char *'} but argument is of type 'CHAR *' {aka 'char *'} 9050 |      PCCH pchString); |     ^ </PRE> Changed  GpiCharStringAt (hps, &ptl, (LONG) strlen (szFacename[iFont]),                          szFacename[iFont]) ; </PRE> to  GpiCharStringAt (hps, &ptl, (LONG) strlen (szFacename[iFont]),                          (PCCH) szFacename[iFont]) ; </PRE>
 * Warning
 * Fix

warning: pointer targets in passing argument 3 of 'GpiCharString' differ in signedness [-Wpointer-sign]
 vf01.c:46:36: warning: pointer targets in passing argument 3 of 'GpiCharString' differ in signedness [-Wpointer-sign] 46 |          GpiCharString (hps, 10L, " - abcdefg") ; |                                   ^      |                                    |      |                                    char * In file included from C:/usr/include/os2.h:39, from vf01.c:6: C:/usr/include/os2emx.h:9048:57: note: expected 'PCCH' {aka 'const unsigned char *'} but argument is of type 'char *' 9048 | LONG APIENTRY GpiCharString (HPS hps, LONG lCount, PCCH pchString); |                                                   ^ </PRE> Changed  GpiCharString (hps, 10L, " - abcdefg") ; </PRE> to  GpiCharString (hps, 10L, (PCCH) " - abcdefg") ; </PRE>
 * Warning
 * Fix

warning: missing braces around initializer
 vectfont.c:55:34: warning: missing braces around initializer [-Wmissing-braces] 55 |                   vectfont [] = { |                                 ^ </PRE> Changed  vectfont [] = { IDM_NOTHING,    NULL, IDM_24POINT,    Display_24Point, IDM_MIRROR,     Display_Mirror, IDM_STRETCH,    Display_Stretch, IDM_CHARANGLE,  Display_CharAngle, IDM_ROTATE,     Display_Rotate, IDM_CHARSHEAR,  Display_CharShear, IDM_SHADOW,     Display_Shadow, IDM_HOLLOW,     Display_Hollow, IDM_DROPSHADOW, Display_DropShadow, IDM_BLOCK,      Display_Block, IDM_NEON,       Display_Neon, IDM_FADE,       Display_Fade, IDM_SPOKES,     Display_Spokes, IDM_WAVY,       Display_Wavy, IDM_MODSPOKES,  Display_ModSpokes } ; </PRE> To  vectfont [] = { {IDM_NOTHING,    NULL}, {IDM_24POINT,    Display_24Point}, {IDM_MIRROR,     Display_Mirror}, {IDM_STRETCH,    Display_Stretch}, {IDM_CHARANGLE,  Display_CharAngle}, {IDM_ROTATE,     Display_Rotate}, {IDM_CHARSHEAR,  Display_CharShear}, {IDM_SHADOW,     Display_Shadow}, {IDM_HOLLOW,     Display_Hollow}, {IDM_DROPSHADOW, Display_DropShadow}, {IDM_BLOCK,      Display_Block}, {IDM_NEON,       Display_Neon}, {IDM_FADE,       Display_Fade}, {IDM_SPOKES,     Display_Spokes}, {IDM_WAVY,       Display_Wavy}, {IDM_MODSPOKES,  Display_ModSpokes} } ; </PRE>
 * Warning
 * Fix

expected '=', ',', ';', 'asm' or '__attribute__' before
 APP.h:26:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'KidWndProc' 26 | MRESULT FAR PASCAL KidWndProc ( HWND, USHORT, MPARAM, MPARAM ); </PRE>
 * Error

Changed  MRESULT FAR PASCAL KidWndProc	 ( HWND, USHORT, MPARAM, MPARAM ); </PRE> to  MRESULT EXPENTRY KidWndProc	 ( HWND, USHORT, MPARAM, MPARAM ); </PRE>
 * Fix

MIN / MAX Missing
 atccnr.c: In function 'CnrSubclassWndProc': atccnr.c:768:33: warning: implicit declaration of function 'min'; did you mean ' main'? [-Wimplicit-function-declaration] 768 |            arcp.lP = arcp.lQ = min (rclCnr.xRight, rclCnr.yTop) / 9; |                                ^      |                                 main make: *** No rule to make target `-o', needed by `atccnr.exe'. Stop. </PRE>
 * Warning

Include to the .H file the following missing:  </PRE> Seems like an old .H file that came with OS/2 used to have that declared and now is missing.
 * Fix
 * 1) ifndef max
 * 2) define max(a,b) (((a) > (b)) ? (a) : (b))
 * 3) endif
 * 4) ifndef min
 * 5) define min(a,b) (((a) < (b)) ? (a) : (b))
 * 6) endif

line(20): protmode
 Warning! W1058: file ldSBPZPt.: line(20): protmode option not valid for an OS/2 EMX executable </PRE> Check the protmode on the .def file. In this case it was empty so I removed it. It was not needed.
 * Warning
 * Fix

returning 'int' from a function with return type 'MRESULT'
<PRE> randrect.c:90:28: warning: returning 'int' from a function with return type 'MRESULT' {aka 'void *'} makes pointer from integer without a cast [-Wint-conversion] 90 |                    return 1 ; |                           ^ </PRE> Changed <PRE> return 1 ; </PRE> for <PRE> return (MRESULT) TRUE </PRE>
 * Warning
 * Fix

Change for: <PRE> return ((MRESULT)TRUE) ; </PRE>
 * Fix2

warning: comparison between pointer and integer
<PRE> randrect.c:47:20: warning: comparison between pointer and integer 47 |     if (hwndFrame != NULL) </PRE> Changed <PRE> if (hwndFrame != NULL) </PRE> to <PRE> if (hwndFrame != '\0') </PRE>
 * Warning
 * Fix

UNDEF
<PRE> gcc -Zomf atccnr.obj atccnr.res atccnr.def -o atccnr.exe weakld: error: Unresolved symbol (UNDEF) 'ClientWndProc'. weakld: info: The symbol is referenced by: C:/dev/DEV-SAMPLES-PM-Air_Traffic_Control_Container/atccnr.DEF Error! E2028: ClientWndProc is an undefined reference Error! E2044: exported symbol ClientWndProc not found make: *** [atccnr.exe] Error 1
 * Warning

</PRE> Removed the EXPORTS from "atccnr.DEF".
 * Fix

warning: format '%ld' expects argument of type 'long int'
<PRE> atccnr.c:485:30: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'int' [-Wformat=] 485 |        sprintf (szBuf, "%s%ld", apszCallSignPrefixes [rand % cPrefixes],      |                            ^      |                              |      |                              long int      |                            %d  486 |      rand % 1000); |     ~                 |             |      |             int </PRE> Changed <PRE> sprintf (szBuf, "%s%ld", apszCallSignPrefixes [rand % cPrefixes],					rand % 1000); </PRE> to <PRE> sprintf (szBuf, "%s%d", apszCallSignPrefixes [rand % cPrefixes],					rand % 1000); </PRE>
 * Warning
 * Fix

warning: pointer targets in initialization of 'unsigned char *'
<PRE> atccnr.c: In function 'InsertContainerRecords': atccnr.c:437:50: warning: pointer targets in initialization of 'unsigned char *' from 'char *' differ in signedness [-Wpointer-sign] 437 |    static const PSZ apszCallSignPrefixes [] = { "AA", "DA", "UA", "TW" }; |                                                 ^ atccnr.c:437:50: note: (near initialization for 'apszCallSignPrefixes[0]') atccnr.c:437:56: warning: pointer targets in initialization of 'unsigned char *' from 'char *' differ in signedness [-Wpointer-sign] 437 |    static const PSZ apszCallSignPrefixes [] = { "AA", "DA", "UA", "TW" }; |                                                       ^ atccnr.c:437:56: note: (near initialization for 'apszCallSignPrefixes[1]') atccnr.c:437:62: warning: pointer targets in initialization of 'unsigned char *' from 'char *' differ in signedness [-Wpointer-sign] 437 |    static const PSZ apszCallSignPrefixes [] = { "AA", "DA", "UA", "TW" }; |                                                             ^ atccnr.c:437:62: note: (near initialization for 'apszCallSignPrefixes[2]') atccnr.c:437:68: warning: pointer targets in initialization of 'unsigned char *' from 'char *' differ in signedness [-Wpointer-sign] 437 |    static const PSZ apszCallSignPrefixes [] = { "AA", "DA", "UA", "TW" }; |                                                                   ^ atccnr.c:437:68: note: (near initialization for 'apszCallSignPrefixes[3]') </PRE> All these signed/unsigned character warnings can be resolved by adding "-DOS2EMX_PLAIN_CHAR" to the compiler flags. See 'os2emx.h' for details. <PRE> gcc -Wall -Zomf -DOS2EMX_PLAIN_CHAR -c -O2 atccnr.c -o atccnr.obj </PRE>
 * Warning
 * Fix

cdecl - error: expected '=', ',', ';', 'asm' or '__attribute__' before 'main'
<PRE> browse.h:12:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'main' 12 | int cdecl main(int, char *[]); |          ^
 * Error

</PRE> Changed <PRE> int cdecl main(int, char *[]); </PRE> to <PRE> int _cdecl main(int, char *[]); </PRE>
 * Fix

VOID Main issue
<PRE> Issue on main </PRE> Changed <PRE> VOID main( VOID ) </PRE> to <PRE> int main( VOID ) </PRE>
 * Error
 * Fix

warning: implicit declaration of function 'rand' [-Wimplicit-function-declaration]
<PRE> game.c:48:17: warning: implicit declaration of function 'rand' [-Wimplicit-function-declaration] 48 |   pgs->playx = rand%35; |                ^ </PRE> It may be that you are forgetting some .h where the function is declared.
 * Error
 * Fix

Included on game.c
 * 1) include <stdlib.h>

VOID _CDECL FAR runThread(PCALCPARM);
<PRE> VOID _CDECL FAR runThread(PCALCPARM); </PRE> Changed <PRE> VOID _CDECL FAR runThread(PCALCPARM); </PRE> to <PRE> VOID FAR runThread(PCALCPARM); </PRE>
 * Error
 * Fix

dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
<PRE> pmcolour.c: In function 'DlgProc': pmcolour.c:116:23: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 116 |     *cwdata->rgb = *((RGB *) &mp1); |                     ~^ </PRE> Changed Added -O1 on the compile process to remove warning. <PRE> gcc -Wall -Zomf -c -O1 pmcolour.c -o pmcolour.obj </PRE>
 * Error
 * Fix

warning: missing braces around initializer [-Wmissing-braces]
<PRE> clipbrd.c:160:25: warning: missing braces around initializer [-Wmissing-braces] 160 | DRIVDATA   drvdata[] = {44L, 0L, "DISPLAY", 0L}; |                        ^      |                          {                   { }} </PRE> Changed <PRE> DRIVDATA   drvdata[] = {44, 0L, "DISPLAY", 0L}; </PRE> for <PRE> DRIVDATA   drvdata[] = ; </PRE>
 * Error
 * Fix

warning: suggest parentheses around assignment used as truth value [-Wparentheses]
<PRE> show.c:107:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 107 |   if ( rc = DirectScreenDisplay ( pbImageBottom, |        ^~
 * Error

</PRE> Changed <PRE> if ( rc = DirectScreenDisplay ( pbImageBottom, pbBMP + 14 + pbmfHeader->bmp2.cbFix, pbmfHeader->bmp2.cx, pbmfHeader->bmp2.cy ) ) </PRE> for <PRE> if ( ( rc = DirectScreenDisplay ( pbImageBottom, pbBMP + 14 + pbmfHeader->bmp2.cbFix, pbmfHeader->bmp2.cx, pbmfHeader->bmp2.cy ) ))
 * Fix

</PRE>

Change to WLINK
You need to add: set EMXOMFLD_TYPE=WLINK set EMXOMFLD_LINKER=wl.exe Remember that the Wacom Linker is "wl.exe" and is on the "watcom-wlink-hll" RPM package.

Change to WRC
You need to add: SET EMXOMFLD_RC_TYPE=WRC SET EMXOMFLD_RC=wrc.exe Remember that the Wacom Resource Compiler is "wrc.exe" and it is on the "watcom-wrc" RPM Package

Resource Compiler
Reading binary resource file walker.res (0) RC: error - Only integer TYPE allowed. RC: 1 error detected make: *** [walker.exe] Error 1
 * Error 1
 * It is possible of an error on the SET INCLUDE directory. Type %INCLUDE% and check if it is pointing to the directory that contains OS2.H

[E:\PROJECTS\SAMPLEPACK\PMWALKER]make  2>&1  | tee make.out wrc -r walker.rc Open Watcom Windows and OS/2 Resource Compiler Version 2.0beta1 LA Portions Copyright (c) 1993-2002 Sybase, Inc. All Rights Reserved. Source code is available under the Sybase Open Watcom Public License. See http://www.openwatcom.org/ for details. walker.rc(2): Error! E062: Unable to open 'os2.h' make: *** [walker.res] Error 9
 * Error 2


 * It is possible of an error on the SET INCLUDE directory. Type %INCLUDE% and check if it is pointing to the directory that contains OS2.H

Generate DLL

 * https://github.com/OS2World/DEV-SAMPLES-C-PM-edctl1/blob/master/makefile
 * https://github.com/OS2World/UTIL-FILE-NewFileManager/blob/master/makefile

Generate / Link LIB

 * https://github.com/OS2World/DEV-SAMPLES-C-PM-edctl1/blob/master/makefile
 * https://github.com/OS2World/UTIL-FILE-NewFileManager/blob/master/makefile

Generate HLP

 * https://github.com/OS2World/DEV-SAMPLES-C-PM-AirTrafficControlContainer/blob/master/makefile
 * https://github.com/OS2World/DEV-SAMPLES-C-PM-framctl/blob/master/framctl1/makefile
 * https://github.com/OS2World/DEV-SAMPLES-C-PM-Template/blob/main/makefile

Link MMPM - DIVE

 * https://github.com/OS2World/DEV-SAMPLES-C-PM-DIVE-ShowJet/blob/main/makefile

Using DIFF
Yes, to catch the changes, something like cp makefile makefile.orig (could be makefile.bak or whatever), then after making changes,

diff -u makefile.orig makefile > makefile.patch

Can also do whole directories, cp newfilemanager/ newfilemanager.orig or such, then from above the directory, diff -ru newfilemanager/ newfilemanager.orig/ > newfilemanager.diff

Which made a huge patch here. Make clean did not clean everything is the big problem, in both directories. There's other options such as -w to ignore white space, which IIRC includes line endings diff --help | less to see all the options There's also git diff, svn diff and such to create similar patches that can be applied much the same way tasking care with the -p parameter. Patch will let you know if it can't find the files to patch or ask about a reversed patch if already applied. Reversed patching undoes a patch, see the help.