Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Example 3: Compiling a C source program that is located in a POSIX file and uses POSIX library functions

&pagelevel(4)&pagelevel

The C source program exists as a POSIX source file with the name hello.c in the directory /USERIDXY/source. The program uses POSIX library functions. The compiler generates an LLM and writes it to a POSIX object file with the default name hello.o. This object file is stored in the directory of the source program. The object file is then processed further in the POSIX shell environment.

Source program file hello.c

#include <stdio.h>
FILE *fp;
int main(void)
{
  printf("Hello, I am a C program\n");
  fp = fopen("/USERIDXY/posixfiles/hello", "w");
  fputs("hello", fp);
  fclose(fp);
  return 0;
}

The source program was created with EDT and saved with the statement @XWRITE FILE=/USERIDXY/source/hello.c.

Runtime listing for compilation, linkage and execution

(IN)   indicates user inputs
(OUT)  indicates system program messages
(IN)   /START-CPLUS-COMPILER ——————————————————————————————————————————  (1) 
(OUT)  %  BLS0523 ELEMENT ’SDFCC’, VERSION ’04.0B02’, TYPE ’L’ FROM LIBRARY
         ’:P401:$TSOS.SYSLNK.CPP.040’ IN PROCESS
(OUT)  %  BLS0524 LLM ’SDFCC’, VERSION ’04.0B02’ OF ’2023-04-02 13:40:11’ 
          LOADED
(OUT)  %  BLS0551 COPYRIGHT (C) 2023 Fujitsu Technology Solutions GmbH. ALL
          RIGHTS RESERVED
(OUT)  %  CDR9992 : BEGIN C/C++ VERSION 04.0B02
(IN)   //MOD-SOURCE-PROP LANG=*C,DEFINE=_OSD_POSIX ————————————————————  (2) 
(IN)   //MOD-INCL-LIB STD-INCL=($.SYSLIB.POSIX-HEADER,*STANDARD-LIB) ——  (3) 
(IN)   //COMPILE SOURCE='/USERIDXY/source/hello.c',-
       //MODULE-OUTPUT=*SOURCE-LOC ————————————————————————————————————  (4) 
(OUT)  %  CDR9907 : NOTES: 0  WARNINGS: 0  ERRORS: 0  FATALS: 0
(OUT)  %  CDR9937 : MODULES GENERATED, CPU TIME USED: 0.3829 SECONDS
(IN)   //END ——————————————————————————————————————————————————————————  (5) 
(OUT)  %  CDR9936 END; SUMMARY: NOTES: 0  WARNINGS: 0  ERRORS: 0  FATALS: 0 
(OUT)  %  CCM0998 CPU TIME USED: 0.3829 SECONDS
(IN)   /START-POSIX-SHELL —————————————————————————————————————————————  (6) 
(OUT)  POSIX Basisshell 10.0A45 created Jun 14 2016
       POSIX Shell 10.0A45 created Jul 12 2016
       Copyright (C) Fujitsu Technology Solutions 2009
                     All Rights reserved
       Last login: Thu Mar 26 10:45:44 2020 on term/002
(IN)   cd source ——————————————————————————————————————————————————————  (7) 
(IN)   ls hello* ——————————————————————————————————————————————————————  (8) 
(OUT)  hello.c    hello.o
(IN)   cc hello.o —————————————————————————————————————————————————————  (9) 
(IN)   a.out —————————————————————————————————————————————————————————— (10) 
(OUT)  Hello, I am a C program

(1)

The compiler run is started.

(2)

The MODIFY-SOURCE-PROPERTIES statement activates the C language mode (the C++ mode is set by default) and sets the _OSD_POSIX define required for the use of POSIX library functions.

(3)

The library containing the standard headers for POSIX library functions is assigned with the MODIFY-INCLUDE-LIBRARY statement in addition to the CRTE library $.SYSLNK.CRTE (*STANDARD-LIBRARY).

(4)

The COMPILE statement is issued to start the compilation run. The absolute path name of the POSIX source file to be compiled is specified with the SOURCE option. POSIX file names must always be enclosed within single quotes. The operand value *SOURCE-LOCATION in the MODULE-OUTPUT option causes the compiled module to be written to a POSIX object file with the default name hello.o and stored in the directory of the source program.

(5)

The compiler run is terminated with the END statement.

(6)

Since POSIX object files can only be processed further in the POSIX subsystem, the POSIX command START-POSIX-SHELL is used to switch from the BS2000 system environment (SDF) to the POSIX environment (shell). The call places the user in the home directory of the current BS2000 user ID (USERIDXY).

(7)

The POSIX command cd is used to change to the source directory in which the source program and the object file generated by the compiler are located.

(8)

On entering the POSIX command ls, the source file hello.c and the object file hello.o are listed.

(9)

The POSIX command cc links the object file hello.o into an executable unit and places it in an executable POSIX file with the default name a.out. The cc command is described in detail in the manual “POSIX Commands of the C/ C++ Compiler” [1].

(10)

The program is executed.