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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #30 on: April 01, 2022, 06:04:38 pm »
Hi

Just chatting with Tellie, he let me know that "kbuild-make" is the package that has the make.exe file. I also installed that one and worked.

Regards
« Last Edit: April 01, 2022, 06:13:01 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #31 on: April 02, 2022, 02:09:43 am »
Hi Martin, looking good. The comments at the beginning of the makefile could be updated and in walker.txt, refer to kbuild-make. When you upload, perhaps update the date in the description line in the def.
Thanks

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #32 on: April 10, 2022, 04:49:38 pm »
Hi

I had also tried the BitCat sample. It compiled fine, but it gave me a lot warnings, but in my limited skill I read the warnings, read the EDM/2 wiki and updated some USHORT to ULONG, NULL to Zeros, changed BITMAPINFOHEADER to BITMAPINFOHEADER2 and BITMAPINFO to BITMAPINFO2 ...and now compiles with no warning.

It compiles with nmake. My issue is that with "make" it also compiles but gives me this warning:
Quote
ld.exe: malformed input file (not rel or archive) bitcat2.exe
make: *** [bitcat2] Error 1

Check attached file.

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #33 on: April 10, 2022, 05:24:01 pm »
Hi Martin, good job fixing the warnings, though if we turn on all warnings by adding -Wall to the bitcat2.obj rule, there are these,
Code: [Select]
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 *'}
 6138 | BOOL APIENTRY WinRegisterClass (HAB hab, PCSZ pszClassName, PFNWP pfnWndProc,
      |                                          ~~~~~^~~~~~~~~~~~
bitcat2.c:39:53: warning: pointer targets in passing argument 4 of 'WinCreateStdWindow' differ in signedness [-Wpointer-sign]
   39 |                                      &flFrameFlags, szClientClass, NULL,
      |                                                     ^~~~~~~~~~~~~
      |                                                     |
      |                                                     CHAR * {aka char *}
In file included from W:/usr/include/os2.h:39,
                 from bitcat2.c:4:
W:/usr/include/os2emx.h:6003:33: note: expected 'PCSZ' {aka 'const unsigned char *'} but argument is of type 'CHAR *' {aka 'char *'}
 6003 |     PULONG pflCreateFlags, PCSZ pszClientClass, PCSZ pszTitle,
      |                            ~~~~~^~~~~~~~~~~~~~
bitcat2.c: In function 'ClientWndProc':
bitcat2.c:70:57: warning: pointer targets in passing argument 3 of 'DevOpenDC' differ in signedness [-Wpointer-sign]
   70 |                   hdcMemory = DevOpenDC(hab, OD_MEMORY, "*", 0L, NULL, 0);
      |                                                         ^~~
      |                                                         |
      |                                                         char *
In file included from W:/usr/include/os2.h:39,
                 from bitcat2.c:4:
W:/usr/include/os2emx.h:9979:51: note: expected 'PCSZ' {aka 'const unsigned char *'} but argument is of type 'char *'
 9979 | HDC APIENTRY DevOpenDC (HAB hab, LONG lType, PCSZ pszToken, LONG lCount,
      |                                              ~~~~~^~~~~~~~
gcc -Zomf bitcat2.obj bitcat2.def -o bitcat2.exe

As for the error you see, GNU make is helpfully trying to do the first rule, "bitcat2 : bitcat2.exe" and compile bitcat2. Fix is to change bitcat2 to all so the first rule is "all : bitcat2.exe"

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #34 on: April 10, 2022, 06:37:38 pm »
Thanks Dave for the tip.

1) I changed to:
 all : bitcat2.exe
Now make does not gives me the warning. 

2) I replaced
 static CHAR  szClientClass[] = "BitCat2";
for
 unsigned char     szClientClass[] = "BitCat2";
and two warnings down.

3) I have no idea what to do with the warning on line 70.  The sample on the INF file says "*" is fine, but I guess it asks me to declare it as "unsigned char" ?


Regards
« Last Edit: April 10, 2022, 07:01:37 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #35 on: April 11, 2022, 12:33:00 am »
Hi again,
3) I have no idea what to do with the warning on line 70.  The sample on the INF file says "*" is fine, but I guess it asks me to declare it as "unsigned char" ?

The Presentation Manager Programing Guide and Ref has this for syntax,
Code: [Select]
This function creates a device context.


#define INCL_DEV /* Or use INCL_PM, Also in COMMON section */
#include <os2.h>

HAB             hab;       /*  Anchor-block handle. */
LONG            lType;     /*  Type of device context: */
PSZ             pszToken;  /*  Device-information token. */
LONG            lCount;    /*  Number of items. */
PDEVOPENDATA    pdopData;  /*  Open-device-context data area. */
HDC             hdcComp;   /*  Compatible-device-context handle. */
HDC             hdc;       /*  Device-context handle: */

hdc = DevOpenDC(hab, lType, pszToken, lCount,
        pdopData, hdcComp);


So I cast the "*" to PSZ and combined with your fix, no more warnings. Whether in this case if that's the best fix, I think so but perhaps someone with better understanding can chime in as I'm not sure of the size of PSZ
Code: [Select]
H:\tmp\BitCat>diff -u BITCAT2.C.orig BITCAT2.C
--- BITCAT2.C.orig      2022-04-10 09:34:22.000000000 -0700
+++ BITCAT2.C   2022-04-10 15:13:00.000000000 -0700
@@ -16,7 +16,7 @@

 int main(void)
    {
-      static CHAR       szClientClass[] = "BitCat2";
+      unsigned char     szClientClass[] = "BitCat2";
       static ULONG      flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
                                        FCF_SIZEBORDER    | FCF_MINMAX   |
                                        FCF_SHELLPOSITION | FCF_TASKLIST;
@@ -67,7 +67,7 @@
       switch(msg)
          {
             case WM_CREATE:
-                  hdcMemory = DevOpenDC(hab, OD_MEMORY, "*", 0L, NULL, 0);
+                  hdcMemory = DevOpenDC(hab, OD_MEMORY, (PSZ)"*", 0L, NULL, 0);


                   sizl.cx = 0;
                   sizl.cy = 0;

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #36 on: April 11, 2022, 12:40:34 am »
Thinking about it, perhaps you should have changed the static CHAR to static unsigned char. The static keyword controls where the memory for the variable is allocated, IIRC, static is heap instead of stack.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #37 on: April 11, 2022, 02:18:31 am »
Thanks Dave.

I followed your advice and I no longer had any warnings. I guess that's is with this sample. I will work on the readme file and upload it later to hobbes.

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #38 on: April 11, 2022, 04:05:22 am »
Good. Further reading of the documentation says the cast and the warning were harmless as "*" means no information taken from the initialization file. So looks good and always nice not to have warnings.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #39 on: April 11, 2022, 10:28:40 pm »
Thanks Dave

I updated but Gits.
- https://github.com/OS2World/DEV-SAMPLES-PM-PMWalker2
- https://github.com/OS2World/DEV-SAMPLES-PM-BitCat

I will keep trying some other PM samples with gcc and post back.

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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #40 on: April 12, 2022, 03:11:02 am »
Hi

I tried this sample "Boxes 3", I had fixed the some warning and it compiles. It says it is a "OS/2 PM program that draws nested boxes in client window", but when I run it, it runs on the background and I can not see anything.

I got this warning that I don't know what it refers to:
Quote
boxes3.rc
gcc -Zomf boxes3.obj boxes3.def -o boxes3.exe
Warning! W1058: file ld1lfMJw.: line(20): protmode option not valid for an OS/2 EMX executable
rc boxes3.res

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #41 on: April 12, 2022, 06:36:58 am »
Hi Martin, the PROTMODE statement is for whether the program runs in real or protected mode, which doesn't make sense for 32 bit OS/2 but is silently ignored by the IBM linkers, best is to simply remove it.
The program is weird, maybe written for OS/2 1.1? I got it to show up in the window list with this patch. At least now it is easy to kill :)
Code: [Select]
H:\tmp\boxes>diff -u BOXES3.C.orig BOXES3.C
--- BOXES3.C.orig       2022-04-11 21:08:42.000000000 -0700
+++ BOXES3.C    2022-04-11 21:17:24.000000000 -0700
@@ -25,8 +25,7 @@
      QMSG        qmsg ;

      ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
-                      FCF_MINMAX | FCF_TASKLIST | FCF_ICON | FCF_ACCELTABLE |
-                      FCF_MENU;
+                      FCF_MINMAX | FCF_TASKLIST;
      const unsigned char szTitle [] = "Boxes";

      hab = WinInitialize (0) ;
@@ -41,18 +40,13 @@

      hwndFrame = WinCreateStdWindow (
                     HWND_DESKTOP,       /* Parent window handle            */
-                    WS_VISIBLE          /* Style of frame window           */
-                         | FS_SIZEBORDER
-                         //| WC_TITLEBAR
-                         | FID_SYSMENU
-                         | FID_MINMAX
-                         | VK_MENU,
+                    WS_VISIBLE,          /* Style of frame window           */
                     &flFrameFlags,      /* Client window class name        */
                     szClientClass,      /* Title bar text                  */
-                    szTitle,
+                    NULL,
+                    0L,
                     0,                 /* Style of client window          */
                     0,                 /* Module handle for resources     */
-                    ID_MAINMENU,        /* ID of resources                 */
                     &hwndClient) ;      /* Pointer to client window handle */

      while (WinGetMsg (hab, &qmsg, 0, 0, 0))

Looking at the msg queue, instead of the usual CASE WM_CREATE, it starts with CASE WM_COMMAND. Probably the whole queue thing needs to be rewritten, which I'm not knowledgeable enough to do. Need to find my OS/2 programming for Dummies book :)
Perhaps someone with more knowledge can chime in.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #42 on: April 12, 2022, 07:18:32 am »
Meanwhile I was playing with adding a bldlevel string to Bitcat. Need https://88watts.net/download/addtofile-1.03.zip on the path or in the program directory.
Here's a first try at updating the makefile to output this,
Code: [Select]
[H:\tmp\BitCat]bldlevel bitcat2.exe
Build Level Display Facility Version 6.12.675 Sep 25 2001
(C) Copyright IBM Corporation 1993-2001
Signature:       @#OS2World:0.4.0#@##1## 11 Apr 2022 20:53:25     ARCAOS-444::::0::V0.4.0@@Bitmap Demo Program
Vendor:          OS2World
Revision:        0.04.0
Date/Time:       11 Apr 2022 20:53:25
Build Machine:   ARCAOS-444
FixPak Version:  V0.4.0
File Version:    0.4
Description:     Bitmap Demo Program

The Gnu Makefile,
Code: [Select]
# gmake makefile
#
# Tools used:
#  Compile::Resource Compiler
#  Compile::GNU C
#  Make: GNU make
#  https://88watts.net/download/addtofile-1.03.zip for AddToFile.cmd

all : bitcat2.exe

bitcat2.exe : bitcat2.obj bitcat2.def
gcc -Zomf bitcat2.obj bitcat2.def -o bitcat2.exe

bitcat2.obj : bitcat2.c bitcat2.h
gcc -Wall -Zomf -c -O2 bitcat2.c -o bitcat2.obj

bitcat2.def : AddToFile.tmp
@echo Building DEF file
$(shell echo NAME            BitCat2 WINDOWAPI > bitcat2.def)
$(shell cat AddToFile.tmp >> bitcat2.def)

AddToFile.tmp :
@echo Building description for bldlevel
$(shell AddToFile.cmd AddToFile.tmp,description,BLDLEVEL,OS2World,0.4.0,Bitmap Demo Program,V0.4.0)

clean :
rm -rf *.exe *.RES *.obj *.def *.tmp

Do a make clean and then make. Some of this stuff should be in variables, tomorrow maybe.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #43 on: April 12, 2022, 03:07:39 pm »
Hi

Just as a note to myself and any comments are welcome.

I created a new development VM with ArcaOS 5.0.7 just with the goal to compile my samples, since my other VM had a lot of other dev software that I was not using with some the stuff on the config.sys. I wanted to started clean.

To recover my status of being able to compile these samples I did:
1) yum install gcc libc-devel binutils kbuild-make
2) SET INCLUDE=C:\usr\include; on Config.sys
3) Got "ilink50.zip" and put the exe on C:\sys\bin and DLLs on c:\sys\dll
(I guess there is no ilink on the rpm)

With that I have the basic stuff to compile the samples again.

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

Silvan Scherrer

  • Full Member
  • ***
  • Posts: 200
  • Karma: +1/-0
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #44 on: April 12, 2022, 04:10:00 pm »
Hi

Just as a note to myself and any comments are welcome.

I created a new development VM with ArcaOS 5.0.7 just with the goal to compile my samples, since my other VM had a lot of other dev software that I was not using with some the stuff on the config.sys. I wanted to started clean.

To recover my status of being able to compile these samples I did:
1) yum install gcc libc-devel binutils kbuild-make
2) SET INCLUDE=C:\usr\include; on Config.sys
3) Got "ilink50.zip" and put the exe on C:\sys\bin and DLLs on c:\sys\dll
(I guess there is no ilink on the rpm)

With that I have the basic stuff to compile the samples again.

Regards
never do 2)
3) use wlink instead of ilink. there is a wlink and wrc rpm.
kind regards
Silvan
CTO bww bitwise works GmbH

Please help us with donations, so we can further work on OS/2 based projects. Our Shop is at https://www.bitwiseworks.com/shop/index.php