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

Martin Iturbide

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

I still need to know why PM Robots does not want to show colors on some BMP files. I need to play with it further.

But for the moment I had compiled PM Maze.
https://github.com/OS2World/GAME-PUZZLE-PM_Maze
And Racer, but that is a command line app
https://github.com/OS2World/GAME-SPORTS-Racer

I fixed all errors and warning according to what I had learn here, and, in PM Maze, also by changing the USHORT to ULONG the program and the menus started working. It is working and the new binary is also on the github.

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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #106 on: May 20, 2023, 04:32:14 pm »
Hi

I'm trying this sample:
https://github.com/OS2World/DEV-SAMPLES-C-PM-Chain

But now I get this error with "chain.res". I checked the makefile but I'm not sure what I'm doing wrong.

Code: [Select]
gcc -Wall -Zomf -c -O2 chain.c -o chain.obj
chain.c: In function 'ClientWndProc':
chain.c:265:17: warning: implicit declaration of function 'SetupChain' [-Wimplicit-function-declaration]
  265 |                 SetupChain();
      |                 ^~~~~~~~~~
chain.c:285:50: warning: passing argument 1 of '_beginthread' from incompatible pointer type [-Wincompatible-pointer-types]
  285 |                 if ( -1 == (tid = _beginthread ( runThread,
      |                                                  ^~~~~~~~~
      |                                                  |
      |                                                  void (*)(CALCPARM *) {aka void (*)(struct <anonymous> *)}
In file included from chain.c:8:
C:/usr/lib/gcc/i686-pc-os2-emx/9/include-fixed/stdlib.h:515:19: note: expected 'void (*)(void *)' but argument is of type 'void (*)(CALCPARM *)' {aka 'void (*)(struct <anonymous> *)'}
  515 | int _beginthread (void (*)(void *), void *, unsigned, void *);
      |                   ^~~~~~~~~~~~~~~~
chain.c: In function 'SetupDlgProc':
chain.c:488:16: warning: returning 'int' from a function with return type 'MRESULT' {aka 'void *'} makes pointer from integer without a cast [-Wint-conversion]
  488 |         return 1;
      |                ^
chain.c: In function 'SetupChain':
chain.c:448:1: warning: control reaches end of non-void function [-Wreturn-type]
  448 | }
      | ^
gcc -Wall -Zomf -c -O2 minsubs.c -o minsubs.obj
gcc -Zomf chain.obj minsubs.obj chain.def -o chain.exe
wrc chain.res
Error! E060: Can't find file "chain.res".
make: *** [chain.exe] Error 9

Some time with the final warnings will be appreciated too.

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5098
  • Karma: +117/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #107 on: May 20, 2023, 05:28:30 pm »
You forgot to add chain.res as a prerequisite for chain.exe.
Code: [Select]
chain.exe:  chain.obj minsubs.obj chain.def chain.res

Now it trps with a sigsegv. The trp gets more informative with adding -g to CFLAGS and LDFLAGS. Fixing the warnings might be enough to fix it. Look later.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #108 on: May 21, 2023, 06:25:46 am »
Thanks Dave, now it compiles, but like you said, it also traps here. Not sure if it can be possible to make it work  :'(
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5098
  • Karma: +117/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #109 on: May 21, 2023, 07:01:43 am »
I think the wrong parameters are fed to _beginthread(), mainly the pointer to runThread(PCALCPARM),  but I'm not knowledgeable enough to know the fix.

Martin Iturbide

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

I did a quick summary of the projects I was able to compile, and I took some time to include a screenshot of the samples I compiled. Here it is the list.
https://github.com/OS2World/DEV-SAMPLES-C-PM-MetaTest
https://github.com/OS2World/DEV-SAMPLES-C-PM-NBEZ
https://github.com/OS2World/DEV-SAMPLES-C-PM-Bug
https://github.com/OS2World/DEV-SAMPLES-C-PM-WindowTemplate
https://github.com/OS2World/DEV-SAMPLES-C-PM-Slider
https://github.com/OS2World/DEV-SAMPLES-C-PM-GPI-Bezier
https://github.com/OS2World/DEV-SAMPLES-C-PM-FastGPI
https://github.com/OS2World/DEV-SAMPLES-C-PM-PMColour
https://github.com/OS2World/DEV-SAMPLES-C-PM-MousDemo
https://github.com/OS2World/DEV-SAMPLES-C-PM-GPI-Revolve
https://github.com/OS2World/DEV-SAMPLES-C-PM-AirTrafficControlContainer
https://github.com/OS2World/DEV-SAMPLES-C-PM-CheckersBoard
https://github.com/OS2World/DEV-SAMPLES-C-PM-LBoxFont
https://github.com/OS2World/DEV-SAMPLES-C-PM-RandRect
https://github.com/OS2World/DEV-SAMPLES-C-PM-RunningBox
https://github.com/OS2World/DEV-SAMPLES-C-PM-PMHello
https://github.com/OS2World/DEV-SAMPLES-C-PM-VectFont
https://github.com/OS2World/DEV-SAMPLES-C-PM-PMWalker2
https://github.com/OS2World/DEV-SAMPLES-C-PM-BitCat
https://github.com/OS2World/DEV-SAMPLES-C-PM-WinTree
https://github.com/OS2World/DEV-SAMPLES-C-PM-ZoomBMP
https://github.com/OS2World/DEV-SAMPLES-C-PM-Slider_2
https://github.com/OS2World/GAME-PUZZLE-PM_Maze
https://github.com/OS2World/GAME-SPORTS-Racer (This is not PM)

Just in case, I saved on github's Releases, the old original version (source code and binaries if apply) and the new release that is compiled under my conditions (gcc, wrc, wl, make), so I'm not deleting any old material if someone wants to go back to different OS/2 version or tools.

I had been fun for the moment. I will check out some other samples.

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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #111 on: May 22, 2023, 08:05:30 pm »
Hi again

I moved on to this sample: https://github.com/OS2World/DEV-SAMPLES-C-PM-ctrldes

It compiles and runs, but I'm think I'm cheating here.
Seems like the goal of the sample is to generate a "controls.dll" file and "driver.exe" that should use that DLL. But I'm compiling driver.exe with everything inside it.

It seems that I don't know how to correctly generate a DLL with the makefile, and make the "exe" to link that.

Help with the makefile is appreciated on this case. 

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5098
  • Karma: +117/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #112 on: May 22, 2023, 10:31:26 pm »
Code: [Select]
--- makefile.orig       2023-05-22 12:59:54.000000000 -0700
+++ makefile    2023-05-22 13:25:20.000000000 -0700
@@ -6,11 +6,14 @@
 #  Make: nmake or GNU make
 all : driver.exe

-driver.exe : driver.obj Controls.obj driver.def
-       gcc -Zomf driver.obj Controls.obj driver.def -o driver.exe
+driver.exe : driver.obj controls.lib driver.def
+       gcc -Zomf -Zmap -lcontrols driver.obj driver.def -o driver.exe

 controls.dll : Controls.obj Controls.def
-       gcc -Zdll -Zomf  Controls.obj Controls.def -o Controls.DLL
+       gcc -Zdll -Zomf -Zmap  Controls.obj Controls.def -o Controls.DLL
+
+controls.lib : Controls.obj Controls.def controls.dll
+       $(shell emximp -o controls.lib Controls.def)

 driver.obj : driver.c Controls.h
        gcc -Wall -Zomf -c -O2 driver.c -o driver.obj
@@ -19,4 +22,4 @@
        gcc -Wall -Zomf -c -O2 Controls.c -o Controls.obj

 clean :
-       rm -rf *exe *RES *obj
\ No newline at end of file
+       rm -rf *exe *RES *obj *lib *dll

The -Zmap is optional. The -lcontrols can also be simply controls.lib
 Controls.def file also needs
Code: [Select]
exports
InitControls

Still seems somewhat broken when executed
Edit: the def file also could be like the original,
Code: [Select]
EXPORTS    InitControls @ 1
if you'd rather export by ordinal
« Last Edit: May 22, 2023, 10:40:34 pm by Dave Yeo »

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #113 on: May 22, 2023, 11:24:14 pm »
Thanks Dave.

It compiled, created the DLL, LIB, EXE files and runs.

Does it looks broken? Maybe, the picture on the article shows the items on the PM window from left to right (Attached).
The article is here: https://archive.org/details/os2devmag/OS2DevMag-V5N2/page/n73

The only issue now when I compile is that "Circular driver.exe <- driver.exe dependency dropped."
Quote
[C:\DEV\DEV-SAMPLES-PM-CRTLDES]make   2>&1  | tee make.out
make: Circular driver.exe <- driver.exe dependency dropped.
gcc -Wall -Zomf -c -O2 driver.c -o driver.obj
gcc -Wall -Zomf -c -O2 controls.c -o controls.obj
gcc -Zdll -Zomf -Zmap  controls.obj controls.def -o controls.dll
gcc -Zomf -Zmap -lcontrols driver.obj driver.def -o driver.exe

It is also interesting that it generates now a control.map and driver.map, which I guess it is some automatic documentation by the Open Watcom Linker.

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5098
  • Karma: +117/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #114 on: May 22, 2023, 11:37:49 pm »
OK, I guess it is correct. You must have left driver.exe in the prerequisites for driver.exe, at least I had to add it to get the circular dependency.
The map files come about from adding -Zmap. Handy for doing things like checking exports, which I added them for, other type of debugging or creating xqs files,
Code: [Select]
mapxqs driver.map
mapxqs Controls.map

Here's my full makefile, renamed to have .txt

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #115 on: May 22, 2023, 11:51:49 pm »
Thanks Dave

I found the silly issue on the makefile comparing it to your file.

It is now done here: https://github.com/OS2World/DEV-SAMPLES-C-PM-ctrldes

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

Lars

  • Hero Member
  • *****
  • Posts: 1367
  • Karma: +70/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #116 on: May 23, 2023, 08:05:49 pm »
Hi

I'm trying this sample:
https://github.com/OS2World/DEV-SAMPLES-C-PM-Chain

Hi Martin,

this is a perfect example where it sometimes makes sense to rewrite the whole thing. This thing was full of bugs (which had nothing to do with being a 16-bit application ...).
Find attached, it should now work.

Lars

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #117 on: May 23, 2023, 09:09:19 pm »
Thanks Lars. Now it compiles and the program is hypnotic.   ;D
I will put it on the github. Thanks.

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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #118 on: May 24, 2023, 03:55:09 am »
Hi

CNRMENU sample compiled and runs without any major issues.
https://github.com/OS2World/DEV-SAMPLES-C-PM-CNRMENU

I just need some help with these warnings.

Code: [Select]
gcc -Wall -Zomf -c -O2 cnrmenu.c -o cnrmenu.obj
wrc -r cnrmenu.rc
Open Watcom Windows and OS/2 Resource Compiler Version 2.0beta4 LA GKYMar  2 2022
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.
gcc -Wall -Zomf -c -O2 common.c -o common.obj
gcc -Wall -Zomf -c -O2 create.c -o create.obj
gcc -Wall -Zomf -c -O2 ctxtmenu.c -o ctxtmenu.obj
ctxtmenu.c: In function 'CtxtmenuSetView':
ctxtmenu.c:375:12: warning: 'strcat' accessing 281 or more bytes at offsets 412 and 692 may overlap 1 byte at offset 692 [-Wrestrict]
  375 |     (void) strcat( pi->szCnrTitle, pi->szDirectory );
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ctxtmenu.c:375:12: warning: 'strcat' accessing 281 or more bytes at offsets 412 and 692 may overlap 1 byte at offset 692 [-Wrestrict]
gcc -Wall -Zomf -c -O2 edit.c -o edit.obj
gcc -Wall -Zomf -c -O2 populate.c -o populate.obj
gcc -Wall -Zomf -c -O2 sort.c -o sort.obj
sort.c: In function 'DateCompare':
sort.c:192:38: warning: '%02u' directive writing between 2 and 3 bytes into a region of size between 1 and 3 [-Wformat-overflow=]
  192 |     (void) sprintf( szDate1,"%04u%02u%02u",date1.year, date1.month, date1.day );
      |                                      ^~~~
sort.c:192:29: note: directive argument in the range [0, 255]
  192 |     (void) sprintf( szDate1,"%04u%02u%02u",date1.year, date1.month, date1.day );
      |                             ^~~~~~~~~~~~~~
sort.c:192:12: note: 'sprintf' output between 9 and 12 bytes into a destination of size 9
  192 |     (void) sprintf( szDate1,"%04u%02u%02u",date1.year, date1.month, date1.day );
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sort.c:193:38: warning: '%02u' directive writing between 2 and 3 bytes into a region of size between 1 and 3 [-Wformat-overflow=]
  193 |     (void) sprintf( szDate2,"%04u%02u%02u",date2.year, date2.month, date2.day );
      |                                      ^~~~
sort.c:193:29: note: directive argument in the range [0, 255]
  193 |     (void) sprintf( szDate2,"%04u%02u%02u",date2.year, date2.month, date2.day );
      |                             ^~~~~~~~~~~~~~
sort.c:193:12: note: 'sprintf' output between 9 and 12 bytes into a destination of size 9
  193 |     (void) sprintf( szDate2,"%04u%02u%02u",date2.year, date2.month, date2.day );
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -Zomf cnrmenu.obj common.obj create.obj ctxtmenu.obj edit.obj populate.obj sort.obj cnrmenu.def -o cnrmenu.exe
Warning! W1058: file lduyj05H.: line(26): protmode option not valid for an OS/2 EMX executable
wrc cnrmenu.res
Open Watcom Windows and OS/2 Resource Compiler Version 2.0beta4 LA GKYMar  2 2022
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.

Regards
« Last Edit: May 24, 2023, 04:56:40 am by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5027
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #119 on: May 26, 2023, 05:18:04 pm »
Hi

This one compiled nice. I was able to remove the warnings.
https://github.com/OS2World/DEV-SAMPLES-C-PM-CNRDTL

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