Author Topic: Compiling a PM sample with GCC (2023)  (Read 95678 times)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4748
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #75 on: May 08, 2023, 04:12:43 am »
Thanks Dave.

I had uploaded the changes to https://github.com/OS2World/DEV-SAMPLES-C-PM-WinTree

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4805
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #76 on: May 08, 2023, 05:46:29 am »
I'd suggest always adding -DOS2EMX_PLAIN_CHAR to CFLAGS.

Lars

  • Hero Member
  • *****
  • Posts: 1272
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #77 on: May 08, 2023, 01:56:05 pm »
Use %u instead of %p. Or, if you want hex output, use %x.

GCC suggests %lu or %lx to fix the warning, and they do. Both work fine, personally I prefer the hex output as well, the original also had hex output.
Edit: Actually I like the capitals that %lX gives.
Hard to find what the l does, from the Linux man page on sprintf()
Code: [Select]
(ell) A following integer conversion corresponds to a long int or unsigned long int argument, or a
 following n conversion corresponds to a pointer to a long int argument, or a following c conversion
corresponds to a wint_t argument, or a following s conversion corresponds to a pointer to wchar_t
argument.

"l" stands explicitely for "long" as "h" explicitely stands for "short". For a 32-bit compiler you do not need to state "l" because that's the default. Likewise, for a 16-bit compiler, you do not need to state "h" as that's the default.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4805
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #78 on: May 08, 2023, 04:15:26 pm »
GCC disagrees, without the l,
Code: [Select]
gcc -Wall -Zomf -DOS2EMX_PLAIN_CHAR -c -O2 wintree.c -o wintree.obj
wintree.c: In function 'TraverseWindows':
wintree.c:150:26: warning: format '%X' expects argument of type 'unsigned int',
but argument 4 has type 'HWND' {aka 'long unsigned int'} [-Wformat=]
  150 |       sprintf(szLine,"%s%X...%s...%s",szLeader, hwndNext, szTitle, szClass);
      |                                       ~^                      ~~~~~~~~
      |                                          |                      |
      |                                         unsigned int           HWND {aka long unsigned int}
      |                                         %lX

The warning goes away with %lX.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4748
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #79 on: May 08, 2023, 08:53:12 pm »
Hi

Now I'm going after PMColour.
https://github.com/OS2World/DEV-SAMPLES-PM-PMColour

It compiled and works with the tools I decided to use. I just have this warning about a pointer that I don't know how to solve it.

Code: [Select]
gcc -Wall -Zomf -c -O2 pmcolour.c -o pmcolour.obj
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);
      |                      ~^~~~~~~~~~~~~
gcc -Zomf pmcolour.obj pmcolour.res pmcolour.def -o pmcolour.exe
wrc pmcolour.res
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.

Any tip is welcome.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4805
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #80 on: May 09, 2023, 01:06:00 am »
Less optimization? Removing the -O2 from CFLAGS does remove the warning with the exe being the same size though likely slightly slower. Otherwise the fixes seem complex from searching the error.
Edit: reducing the optimization to -O1 also removes the warning. Or simply not doing the strict aliasing,
Code: [Select]
pmcolour.obj : pmcolour.c pmcolour.h
               gcc -Wall -Zomf -c -O2 -Wno-strict-aliasing  pmcolour.c -o pmcolour.obj
« Last Edit: May 09, 2023, 01:12:18 am by Dave Yeo »

Lars

  • Hero Member
  • *****
  • Posts: 1272
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #81 on: May 09, 2023, 09:35:05 am »
GCC disagrees, without the l,
Code: [Select]
gcc -Wall -Zomf -DOS2EMX_PLAIN_CHAR -c -O2 wintree.c -o wintree.obj
wintree.c: In function 'TraverseWindows':
wintree.c:150:26: warning: format '%X' expects argument of type 'unsigned int',
but argument 4 has type 'HWND' {aka 'long unsigned int'} [-Wformat=]
  150 |       sprintf(szLine,"%s%X...%s...%s",szLeader, hwndNext, szTitle, szClass);
      |                                       ~^                      ~~~~~~~~
      |                                          |                      |
      |                                         unsigned int           HWND {aka long unsigned int}
      |                                         %lX

The warning goes away with %lX.

Then gcc is a picky smartass.

Lars

  • Hero Member
  • *****
  • Posts: 1272
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #82 on: May 09, 2023, 09:39:31 am »
Hi

Now I'm going after PMColour.
https://github.com/OS2World/DEV-SAMPLES-PM-PMColour

It compiled and works with the tools I decided to use. I just have this warning about a pointer that I don't know how to solve it.

Code: [Select]
gcc -Wall -Zomf -c -O2 pmcolour.c -o pmcolour.obj
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);
      |                      ~^~~~~~~~~~~~~
gcc -Zomf pmcolour.obj pmcolour.res pmcolour.def -o pmcolour.exe
wrc pmcolour.res
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.

Any tip is welcome.

Regards

First, try this: *cwdata->rgb = (RGB)mp1;

If that still does not work, then consult the gcc Compiler's manual and see how you can disable the "strict-aliasing" warning.
"-Wstrict-aliasing" enables it so maybe "-Wno-strict-aliasing" disables it. You will have to find out.


The story behind this warning: first you tell gcc that mp1 is of type MPARAM which effectively evaluates to ULONG aka unsigned long int.
That would mean that &mp1 is a pointer to unsigned long int. Then all of a sudden you tell it that &mp1 is a pointer to an RGB.
Since gcc is a picky smartass it tells you that it's not ok to first claim it is a pointer to an unsigned long int and later claim it is a pointer to an RGB.
« Last Edit: May 09, 2023, 10:09:40 am by Lars »

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4748
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #83 on: May 09, 2023, 06:06:23 pm »
Thanks for the reply and explanation of the warning.

First, try this: *cwdata->rgb = (RGB)mp1;

If I change it I get an error:
Code: [Select]
gcc -Wall -Zomf -c -O2 pmcolour.c -o pmcolour.obj
pmcolour.c: In function 'DlgProc':
pmcolour.c:117:3: error: conversion to non-scalar type requested
  117 |   *cwdata->rgb = (RGB)mp1;
      |   ^
make: *** [pmcolour.obj] Error 1

FYI: If I change the -02 to 01 or enable "-Wno-strict-aliasing", the warning is gone.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4748
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #84 on: May 10, 2023, 07:41:28 pm »
Hi

I'm trying the Wheel Sample: https://github.com/OS2World/DEV-SAMPLES-C-PM-Wheel
I wanted to try a sample with some DLLs. Even that I like the executable sample, it seems too old (compiled with Microsoft C ?) and too confusing with all DLLs and LIB that it includes.

I tried to create a make file to consolidate all the single makefiles, but I'm not sure if I'm doing it right.
I'm attaching my failed try.

Code: [Select]
[C:\DEV\DEV-SAMPLES-C-WHEEL]make   2>&1  | tee make.out
gcc -Wall -Zomf -c -O2 test.c -o test.obj
gcc -Zomf test.obj test.res test.def -o test.exe
weakld: error: Unresolved symbol (UNDEF) 'ColorWheelInitialize'.
weakld: info: The symbol is referenced by:
    C:\dev\DEV-SAMPLES-C-Wheel\test.obj
Ignoring unresolved externals reported from weak prelinker.
Error! E2028: ColorWheelInitialize is an undefined reference
file C:\dev\DEV-SAMPLES-C-Wheel\test.obj(test.obj): undefined symbol ColorWheelI
nitialize
make: *** [test.exe] Error 1

Regards.
« Last Edit: May 10, 2023, 10:51:25 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4805
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #85 on: May 11, 2023, 01:12:25 am »
Fixed your makefile (needs more work) but still get the unresolved symbol error for some reason, calling convention? The symbol is there.
Code: [Select]
--- makefile.orig       2023-05-10 15:37:46.000000000 -0700
+++ makefile    2023-05-10 16:03:22.000000000 -0700
@@ -6,18 +6,24 @@
 #  Make: nmake or GNU make
 all : test.exe

-test.exe : test.obj test.res test.def
-       gcc -Zomf test.obj test.res test.def -o test.exe
+test.exe : test.obj test.res test.def wheel.lib
+       gcc -Zomf -L. -lwheel test.obj test.res test.def -o test.exe
        wrc test.res

 wheel.dll : wheel.def wheel.dll
-       gcc -Zomf wheel.obj wheel.res wheel.def -o wheel.dll
+       gcc -Zdll -Zomf wheel.obj wheel.res wheel.def -o wheel.dll
+
+wheel.lib : $(shell emximp -o wheel.lib wheel.def)

 AllocMem.DLL : AllocMem.def AllocMem.obj AllocMem.res
-       gcc -Zomf AllocMem.obj AllocMem.res AllocMem.def -o AllocMem.dll
+       gcc -Zdll -Zomf AllocMem.obj AllocMem.res AllocMem.def -o AllocMem.dll
+
+AllocMem.lib : $(shell emximp -o AllocMem.lib AllocMem.def)

 telluser.dll : telluser.def telluser.obj
-       gcc -Zomf telluser.obj telluser.def -o telluser.dll
+       gcc -Zdll -Zomf telluser.obj telluser.def -o telluser.dll
+
+telluser.lib : $(shell emximp -o telluser.lib telluser.def)

 test.obj : test.c test.h wheel.h
        gcc -Wall -Zomf -c -O2 test.c -o test.obj
@@ -38,4 +44,4 @@
        wrc -r test.rc

 clean :
-       rm -rf *exe *RES *obj *hlp
+       rm -rf *exe *RES *obj *hlp *lib *LIB

Notes, need -Zdll when building a dll. $(shell runs a cmd. -L. search for libraries in these directories, dot in this case. -lwheel use the wheel library.
This is also fine,
Code: [Select]
-test.exe : test.obj test.res test.def
-       gcc -Zomf test.obj test.res test.def -o test.exe
+test.exe : test.obj test.res test.def wheel.lib
+       gcc -Zomf wheel.lib test.obj test.res test.def -o test.exe
        wrc test.res

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4805
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #86 on: May 11, 2023, 01:27:43 am »
OK, fixed the makefile to get further, lots of errors and warnings while compiling wheel.obj,
Code: [Select]


[code]
--- makefile.orig       2023-05-10 15:37:46.000000000 -0700
+++ makefile    2023-05-10 16:24:36.000000000 -0700
@@ -6,18 +6,24 @@
 #  Make: nmake or GNU make
 all : test.exe

-test.exe : test.obj test.res test.def
-       gcc -Zomf test.obj test.res test.def -o test.exe
+test.exe : test.obj test.res test.def wheel.lib wheel.dll
+       gcc -Zomf wheel.lib test.obj test.res test.def -o test.exe
        wrc test.res

-wheel.dll : wheel.def wheel.dll
-       gcc -Zomf wheel.obj wheel.res wheel.def -o wheel.dll
+wheel.dll : wheel.def wheel.obj
+       gcc -Zdll -Zomf wheel.obj wheel.res wheel.def -o wheel.dll
+
+wheel.lib : $(shell emximp -o wheel.lib wheel.def)

 AllocMem.DLL : AllocMem.def AllocMem.obj AllocMem.res
-       gcc -Zomf AllocMem.obj AllocMem.res AllocMem.def -o AllocMem.dll
+       gcc -Zdll -Zomf AllocMem.obj AllocMem.res AllocMem.def -o AllocMem.dll
+
+AllocMem.lib : $(shell emximp -o AllocMem.lib AllocMem.def)

 telluser.dll : telluser.def telluser.obj
-       gcc -Zomf telluser.obj telluser.def -o telluser.dll
+       gcc -Zdll -Zomf telluser.obj telluser.def -o telluser.dll
+
+telluser.lib : $(shell emximp -o telluser.lib telluser.def)

 test.obj : test.c test.h wheel.h
        gcc -Wall -Zomf -c -O2 test.c -o test.obj
@@ -38,4 +44,4 @@
        wrc -r test.rc

 clean :
-       rm -rf *exe *RES *obj *hlp
+       rm -rf *exe *RES *obj *hlp *lib *LIB *dll *DLL

look better at it later.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4805
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #87 on: May 11, 2023, 04:06:35 am »
Looking better, it seems that it will take some knowledge to port to 32 bit. Things like the semaphore far type I have no idea :)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4748
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #88 on: May 11, 2023, 05:25:34 am »
Thanks for the makefile help.

Now I'm stuck is that "DOSFSRSEM"

Code: [Select]
gcc -Wall -Zomf -c -O2 wheel.c -o wheel.obj
wheel.c: In function 'ColorWheelInitialize':
wheel.c:401:14: error: unknown type name 'DOSFSRSEM'
  401 |      {static DOSFSRSEM dosfsrs;        // Semaphore to block registratio
n
      |              ^~~~~~~~~
wheel.c:402:12: error: unknown type name 'DOSFSRSEM'
  402 |    typedef DOSFSRSEM FAR *PDOSFSRSEM;
      |            ^~~~~~~~~
wheel.c:408:7: warning: implicit declaration of function 'DosFSRamSemRequest' [-
Wimplicit-function-declaration]
  408 |       DosFSRamSemRequest (&dosfsrs, SEM_INDEFINITE_WAIT);
      |       ^~~~~~~~~~~~~~~~~~
wheel.c:429:7: warning: implicit declaration of function 'DosFSRamSemClear' [-Wi
mplicit-function-declaration]
  429 |       DosFSRamSemClear (&dosfsrs);
      |       ^~~~~~~~~~~~~~~~
make: *** [wheel.obj] Error 1


Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Lars

  • Hero Member
  • *****
  • Posts: 1272
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #89 on: May 11, 2023, 07:02:41 am »
This is one of the points where it needs engineering judgement. DOSFRSEM (the various API functions: DosFSRamSemRequest etc.) implements a RAM semaphore and this is no longer supported with 32-bit OS/2 (the OS does no longer offer this, I guess this was decided in order to prevent undermining memory protection).
You will need to use Mutex semaphore instead. See Control Programming reference, search for "Mutex".
« Last Edit: May 11, 2023, 08:54:56 am by Lars »