Building freestanding applications
Freestanding applications need to be linked with specific alternate initialization routines.
To explicitly include an alternative initialization routine under MVS™, use the linkage editor INCLUDE
and ENTRY control statements. To include the alternate
initialization routines described in this topic, you must allocate
CEE.SCEESPC to the SYSLIB DD. For example, the following linkage editor
control stream might be used to specify EDCXSTRT as
an alternate initialization routine (another example is shown in Figure 3):
Figure 1. Specifying
alternate initialization at link-edit time
INCLUDE SYSLIB(EDCXSTRT)
ENTRY EDCXSTRT
INCLUDE SYSIN
When building freestanding applications under MVS, CEE.SCEESPC must be included in the link-edit SYSLIB concatenation. Also, if C library functions are needed, CEE.SCEESPC must precede CEE.SCEELKED.
The routines to support this function (EDCXSTRT and EDCXSTRL) are CEESTART replacements in your module. You must specify NOSTART compiler option when compiling the file that contains the main function. Therefore, the appropriate EDCXSTRn routine must be explicitly included at link-edit.
A simple freestanding routine that requires a C library function
is shown in Figure 2.
Figure 2. Simple freestanding routine
#include <stdio.h>
main() {
puts("Hello, World");
return 3999;
}
This routine, RET3999, is compiled with nostart compiler
option and link-edited using control statements shown in Figure 3. It is assumed that:
- The object module is available to the linkage-editor using an OBJECT DD statement.
- CEE.SCEESPC and CEE.SCEELKED libraries are specified on a SYSLIB DD statement.
- The intended load module member name is specified on a SYSLMOD DD statement.
The CEE.SCEERUN runtime load library must be available at runtime
because it contains the C library function puts().
Figure 3. Link-edit control statements
used to build a freestanding MVS routine
INCLUDE SYSLIB(EDCXSTRL)
INCLUDE OBJECT
ENTRY EDCXSTRL
Figure 4 shows how to compile and
link a freestanding program using the cataloged procedure EDCCL. See z/OS XL C/C++ Programming Guide for
more information about EDCCL.
Figure 4. Compile and link
using EDCCL
//* Appropriate JOB card
//*-----------------------------------------------------------------
//**************************************************
//*** COMPILE AND LINK USING EDCXSTRL AS ENTRY POINT
//**************************************************
//C106001 EXEC EDCCL,
// INFILE='ANDREW.SPC.SOURCE(C106000)',
// OUTFILE='ANDREW.SPC.LOAD(C106000),DISP=SHR',
// CPARM='OPT(2),NOSEQ,NOMAR,NOSTART',
// LPARM='RMODE=ANY,AMODE=31'
//LKED.SYSLIB DD DSN=CEE.SCEESPC,DISP=SHR
// DD DSN=CEE.SCEELKED,DISP=SHR
//LKED.SYSIN DD *
INCLUDE SYSLIB(EDCXSTRL)
ENTRY EDCXSTRL
/*