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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4713
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Compiling a PM sample with GCC
« on: March 30, 2022, 12:06:44 am »
Hi

I'm trying to compile a little PM sample, just for the fun of it.

It is: PMWalker_r2.zip
The make file uses gcc, link386 and rc.

I run nmake and it shows me this error:

Quote
{2}[e:\projects\samplepack\pmwalker_r2] nmake

Operating System/2 Program Maintenance Utility
Version 4.00.001 Oct  4 2001
Copyright (C) IBM Corporation 1988-2001
Copyright (C) Microsoft Corp. 1988-1991
All rights reserved.

        gcc -c -O2 walker.c
walker.c:30:10: fatal error: os2.h: No such file or directory
   30 | #include <os2.h>
      |          ^~~~~~~
compilation terminated.
NMAKE : fatal error U1077: 'C:\SYS\APPS\4OS2\4OS2.EXE' : return code '1'
Stop.

I have OS2.h on "C:\usr\include\os2tk45"  and on the config.sys "SET INCLUDE=C:\usr\include\os2tk45"

Any idea why I have that error? Do I have to use other OS2.h ?

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

Lars

  • Hero Member
  • *****
  • Posts: 1271
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #1 on: March 30, 2022, 01:03:17 am »
gcc.exe does not know about INCLUDE env var. Try C_INCLUDE_PATH instead.

If that does not work , add -Ic:/usr/include/os2tk45 to the compiler commandline in the makefile.
« Last Edit: March 30, 2022, 01:12:33 am by Lars »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #2 on: March 30, 2022, 03:17:55 am »
Actually, GCC wants the os2.h in @unixroot\usr\include and should find it on its own without C_INCLUDE_PATH or -I, if you want to use the one in the toolkit, you need to define USE_OS2_TOOLKIT_HEADERS 1 or edit os2.h around line 39. Should use the define though.
Likewise, if you need  Toolkit header like dive.h, the toolkit headers need to be at the end of the C include search path, C_INCLUDE_PATH=/@unixroot/usr/include;c:/usr/include/os2tk45 or use -Idirafter=c:/usr/include/os2tk45.
Anyways, PMwalker seems to be designed for EMX, after editing the makefile to compile with kLIBC, I get,
Code: [Select]
        gcc -Zomf walker.obj walker.def
weakld: error: Unresolved symbol (UNDEF) '_ClientWndProc'.
weakld: info: The symbol is referenced by:
    H:/tmp/PMwalker/walker.def
Ignoring unresolved externals reported from weak prelinker.
Warning! W1058: file ldZXONto.: line(20): protmode option not valid for an OS/2
EMX executable
Error! E2028: _ClientWndProc is an undefined reference
Error! E2044: exported symbol _ClientWndProc not found
NMAKE : fatal error U1077: 'W:\OS2\CMD.EXE' : return code '1'
Stop.
with this makefile,
Code: [Select]
walker : walker.exe

walker.exe : walker.obj walker.res walker.def
   gcc -Zomf walker.obj walker.def
   rc walker.res

walker.obj : walker.c walker.h
   gcc -Zomf -los2 -c -O2 walker.c -o walker.obj

walker.res : walker.rc step1.ico step2.ico step3.ico
   rc -r walker.rc

Need to read the documentation, probably a define missing.
Hmm, the def file is broken, need to remove the underline prefix so it reads EXPORTS ClientWndProc rather then EXPORTS _ClientWndProc
Edit:, read the readme.txt, it was actually written for a different GCC port, GCC/2, not EMX.
« Last Edit: March 30, 2022, 03:35:43 am by Dave Yeo »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #3 on: March 30, 2022, 03:24:01 am »
Better makefile,
Code: [Select]
walker : walker.exe

walker.exe : walker.obj walker.res walker.def
   gcc -Zomf walker.obj walker.def -o walker.exe
   rc walker.res

walker.obj : walker.c walker.h
   gcc -Zomf -c -O2 walker.c -o walker.obj

walker.res : walker.rc step1.ico step2.ico step3.ico
   rc -r walker.rc

along with the def change compiles and runs fine here, if it isn't finding os2.h in your setup, something is broken.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #4 on: March 30, 2022, 03:50:21 am »
Here's the updated package if you want to upload to Hobbes. Added a clean target to the makefile, nmake clean.

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 #5 on: March 30, 2022, 04:51:47 am »
Thanks Lars, Dave.

Dave, I'm using your sample now.

I did a:
SET C_INCLUDE_PATH=/@unixroot/usr/include;c:/usr/include/os2tk45
run nmake , and I still get some errors:

Quote

Operating System/2 Program Maintenance Utility

Version 4.00.001 Oct  4 2001

Copyright (C) IBM Corporation 1988-2001

Copyright (C) Microsoft Corp. 1988-1991

All rights reserved.

   gcc -Zomf -c -O2 walker.c -o walker.obj
In file included from c:/usr/include/os2tk45/os2.h:33,
                 from walker.c:29:
c:/usr/include/os2tk45/os2def.h:99:28: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PUCHAR16'
   99 | typedef UCHAR     * _Seg16 PUCHAR16;
      |                            ^~~~~~~~
c:/usr/include/os2tk45/os2def.h:100:28: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PCHAR16'
  100 | typedef CHAR      * _Seg16 PCHAR16;
      |                            ^~~~~~~
c:/usr/include/os2tk45/os2def.h:138:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PVOID16'
  138 | typedef VOID   * _Seg16  PVOID16;
      |                          ^~~~~~~
c:/usr/include/os2tk45/os2def.h:144:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PBOOL16'
  144 | typedef BOOL16     * _Seg16 PBOOL16;
      |                             ^~~~~~~
In file included from walker.c:30:
C:/usr/lib/gcc/i686-pc-os2-emx/9/include-fixed/stddef.h:56:10: fatal error: sys/_types.h: No such file or directory
   56 | #include <sys/_types.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
NMAKE : fatal error U1077: 'C:\OS2\CMD.EXE' : return code '1'
Stop.


What else do you think I'm missing? Do I have to make a change on OS2.h?

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 #6 on: March 30, 2022, 05:10:33 am »
You're picking up too much from the toolkit, which conflicts with GCC/kLIBC. You want to end up using os2emx.h (which /usr/include/os2.h calls), not the toolkit os2.h.
Do you have a c:\usr\include\os2.h? Does it still fail with C_INCLUDE_PATH cleared, ie set C_INCLUDE_PATH=
You could check out what the preprocessor thinks by adding -E to the walker.obj gcc line and looking at walker.obj

Lars

  • Hero Member
  • *****
  • Posts: 1271
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #7 on: March 30, 2022, 09:48:34 am »
As Dave suggested, DO NOT use the IBM provided toolkit when it comes to using gcc.exe. Apparently, gcc.exe does not understand some of the specific keywords (like "_Seg16") that the WATCOM and IBM compilers understand.

You should have a \usr\include\os2.h file and, without any further customization, that file will include <os2emx.h> which is basically the "merge" of all individual header files from the IBM toolkit (at least the BSE and PM and WIN related header files). That is by far the easiest way to go for gcc.exe.

I think the IBM provided toolkit files were packaged for those developers that intend to use WATCOM or the IBM provided toolchain (Visual Age C++). Maybe that should have been stated right away ...
« Last Edit: March 30, 2022, 09:59:12 am by Lars »

Lars

  • Hero Member
  • *****
  • Posts: 1271
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #8 on: March 30, 2022, 09:53:52 am »
Actually, GCC wants the os2.h in @unixroot\usr\include and should find it on its own without C_INCLUDE_PATH or -I, if you want to use the one in the toolkit, you need to define USE_OS2_TOOLKIT_HEADERS 1 or edit os2.h around line 39. Should use the define though.
Likewise, if you need  Toolkit header like dive.h, the toolkit headers need to be at the end of the C include search path, C_INCLUDE_PATH=/@unixroot/usr/include;c:/usr/include/os2tk45 or use -Idirafter=c:/usr/include/os2tk45.
Anyways, PMwalker seems to be designed for EMX, after editing the makefile to compile with kLIBC, I get,
Code: [Select]
        gcc -Zomf walker.obj walker.def
weakld: error: Unresolved symbol (UNDEF) '_ClientWndProc'.
weakld: info: The symbol is referenced by:
    H:/tmp/PMwalker/walker.def
Ignoring unresolved externals reported from weak prelinker.
Warning! W1058: file ldZXONto.: line(20): protmode option not valid for an OS/2
EMX executable
Error! E2028: _ClientWndProc is an undefined reference
Error! E2044: exported symbol _ClientWndProc not found
NMAKE : fatal error U1077: 'W:\OS2\CMD.EXE' : return code '1'
Stop.
with this makefile,
Code: [Select]
walker : walker.exe

walker.exe : walker.obj walker.res walker.def
   gcc -Zomf walker.obj walker.def
   rc walker.res

walker.obj : walker.c walker.h
   gcc -Zomf -los2 -c -O2 walker.c -o walker.obj

walker.res : walker.rc step1.ico step2.ico step3.ico
   rc -r walker.rc

Need to read the documentation, probably a define missing.
Hmm, the def file is broken, need to remove the underline prefix so it reads EXPORTS ClientWndProc rather then EXPORTS _ClientWndProc
Edit:, read the readme.txt, it was actually written for a different GCC port, GCC/2, not EMX.

Apparently, decades ago, GCC/2 either did not understand the "_System" keyword as a calling convention or the emx header files did not specify the "_System" keyword in which case the compiler defaults to the "C" calling convention that in turn will lead to an underscore being prepended to the symbol name (thank god, the "C" and the "_System" calling conventions have about the same rules regarding argument passing and stack cleanup ...).
If I now look into \usr\include\os2.h and \usr\include\os2emx.h, everything is fine and gcc.exe will properly resolve the EXPENTRY macro definition to the "_System" keyword.
« Last Edit: March 30, 2022, 09:58:16 am by Lars »

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 #9 on: March 30, 2022, 02:56:26 pm »
Hi

I have installed the RPM os2tk45 and it is located on the c:\usr, and also the IBM toolkit installed on D:\OS2TK45.
I had removed all references to the D:\OS2TK45 on the config.sys. I'm using nmake Version 4.00.001.

I'm attaching the OS2.h I have on C:\usr\include\os2tk45

I open a new  4CMD session:
run:
- SET C_INCLUDE_PATH=/@unixroot/usr/include;c:/usr/include/os2tk45
- D:\OS2TK45\bin\nmake 2>&1 |tee make.out

And I get the same error:
Code: [Select]

Operating System/2 Program Maintenance Utility
Version 4.00.001 Oct  4 2001
Copyright (C) IBM Corporation 1988-2001
Copyright (C) Microsoft Corp. 1988-1991
All rights reserved.

gcc -Zomf -c -O2 walker.c -o walker.obj
In file included from c:/usr/include/os2tk45/os2.h:33,
                 from walker.c:29:
c:/usr/include/os2tk45/os2def.h:99:28: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PUCHAR16'
   99 | typedef UCHAR     * _Seg16 PUCHAR16;
      |                            ^~~~~~~~
c:/usr/include/os2tk45/os2def.h:100:28: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PCHAR16'
  100 | typedef CHAR      * _Seg16 PCHAR16;
      |                            ^~~~~~~
c:/usr/include/os2tk45/os2def.h:138:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PVOID16'
  138 | typedef VOID   * _Seg16  PVOID16;
      |                          ^~~~~~~
c:/usr/include/os2tk45/os2def.h:144:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PBOOL16'
  144 | typedef BOOL16     * _Seg16 PBOOL16;
      |                             ^~~~~~~
In file included from walker.c:30:
C:/usr/lib/gcc/i686-pc-os2-emx/9/include-fixed/stddef.h:56:10: fatal error: sys/_types.h: No such file or directory
   56 | #include <sys/_types.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
NMAKE : fatal error U1077: 'C:\SYS\APPS\4OS2\4OS2.EXE' : return code '1'
Stop.


« Last Edit: March 30, 2022, 03:09:36 pm by Martin Iturbide »
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 #10 on: March 30, 2022, 03:26:00 pm »
Hi

Just in case I created a new VM from my ArcaOS 5.0.7 vanilla, installed "yum install gcc os2tk45", copied nmake 4.

I opened a new  4CMD session:
run:
- SET C_INCLUDE_PATH=/@unixroot/usr/include;c:/usr/include/os2tk45
- D:\OS2TK45\bin\nmake 2>&1 |tee make.out

Same error.  Can it be some issue with os2def.h ?

Regards
« Last Edit: March 30, 2022, 04:00:29 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 #11 on: March 30, 2022, 04:36:12 pm »
Have you installed libc-dev? You shouldn't need the toolkit usually with GCC as it has its own version of the toolkit as Lars said.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #12 on: March 30, 2022, 04:47:34 pm »
I think the IBM provided toolkit files were packaged for those developers that intend to use WATCOM or the IBM provided toolchain (Visual Age C++). Maybe that should have been stated right away ...

GCC multimedia apps at least also need to use the toolkit as the EMX (now libc) version is missing them, this includes dive.h and IIRC mmpm2.lib. Trick is including the toolkit at the end of the include search, often with -idirafter.

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 #13 on: March 30, 2022, 08:14:26 pm »
Hi

Thanks, I didn't know that libc-devel had the include files.

So.
- yum install libc-devel
- yum remove os2tk45
and now opened a new  4CMD session:
run:
- SET C_INCLUDE_PATH=/@unixroot/usr/include;c:/usr/include/os2tk45
- nmake 2>&1 |tee make.out

Now I got a new error.
Code: [Select]
Operating System/2 Program Maintenance Utility
Version 4.00.001 Oct  4 2001
Copyright (C) IBM Corporation 1988-2001
Copyright (C) Microsoft Corp. 1988-1991
All rights reserved.

gcc -Zomf -c -O2 walker.c -o walker.obj
gcc.exe: fatal error: cannot execute 'as': spawnvp: No such file or directory
compilation terminated.
NMAKE : fatal error U1077: 'C:\SYS\APPS\4OS2\4OS2.EXE' : return code '1'
Stop.

Using:
- gcc.exe (GCC) 9.2.0 20190812 (OS/2 RPM build 9.2.0-5.oc00)
- nmake  Version 4.00.001
- rc - 4.00.011
« Last Edit: March 30, 2022, 08:19: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 #14 on: March 30, 2022, 08:54:52 pm »
That's weird, as is the GNU compiler, part of GCC. Is as.exe in \usr\bin? Is your PATH correct in having c:\usr\bin near the beginning? Have you tried with cmd.exe instead of 4os2? I only use cmd.exe due to 4os2 acting different in some circumstances and breaking things.
Using the stock 4os2 install, it works fine here,
Code: [Select]
Operating System/2 Program Maintenance Utility
Version 3.00.013 Nov 17 1995
Copyright (C) IBM Corporation 1988-1995
Copyright (C) Microsoft Corp. 1988-1991
All rights reserved.

gcc -Zomf -c -O2 walker.c -o walker.obj
rc -r walker.rc
Operating System/2 Resource Compiler
Version 4.00.011 Oct 10 2000
(C) Copyright IBM Corporation 1988-2000
(C) Copyright Microsoft Corp. 1985-2000
All rights reserved.


Creating binary resource file walker.RES
RC:  RCPP -E -D RC_INVOKED -W4 -f walker.rc -ef W:\OS2\RCPP.ERR -I G:\IBMCPP\INCLUDE -I G:\IBMCPP\INCLUDE\OS2 -I G:\IBMCPP\INC -I G:\IBMCPP\INCLUDE\SOM -I W:\usr\include\os2tk45\inc -I W:\usr\include\os2tk45\gl -I W:\usr\include\os2tk45

walker.rc
gcc -Zomf walker.obj walker.def -o walker.exe
Warning! W1058: file ld3xIFSd.: line(20): protmode option not valid for an OS/2 EMX executable
rc walker.res
Operating System/2 Resource Compiler
Version 4.00.011 Oct 10 2000
(C) Copyright IBM Corporation 1988-2000
(C) Copyright Microsoft Corp. 1985-2000
All rights reserved.


Reading binary resource file walker.res


Writing resources to OS/2 v2.0 Linear .EXE file
Writing 1 DEMAND resource object(s)
  Writing:  5552 bytes in 2 page(s)
    1.1 (1388 bytes)
    2.1 (1388 bytes)
    3.1 (1388 bytes)
    4.1 (1388 bytes)
Writing Extended Attributes:  Default Icon
Writing Extended Attributes:  Checksum

Guess the protmode line could be removed from the def file. The IBM linkers don't complain about it and others have acted surprised about the warning.
« Last Edit: March 30, 2022, 08:56:33 pm by Dave Yeo »