Compiling
The following examples show how to compile a C and C++ source code files under z/OS® UNIX System Services and z/OS batch.
validateArguments.c#include <stdlib.h>
int lookupTable[11];
int getRC(int factor1, int factor2);
int main(int argc, char* argv[]) {
// Validate the argument count
if (argc < 3) {
return 1;
}
if (argc > 3) {
return 2;
}
// Initialize the global data
for (int i = 0; i < 11; i++) {
lookupTable[i] = i;
}
// Convert the arguments to numbers
// Note: argv[0] is the executable name
int factor1 = atoi(argv[1]);
int factor2 = atoi(argv[2]);
return getRC(factor1, factor2);
}
intMap.Cextern int lookupTable[11];
extern "C" {
int getRC(int index1, int index2);
}
int getRC(int index1, int index2) {
for (int i : lookupTable) {
if (i == index1) {
return lookupTable[i] * lookupTable[index2];
}
}
return -1;
}
Under z/OS UNIX System Services
validateArguments.c can be compiled as
follows:ibm-clang -c -Wall validateArguments.c
The ibm-clang invocation
command compiles the C source code under 32-bit non-XPLINK compilation mode. The
-Wall compiler option enables warning of possible code issues.
intMap.C can be compiled with the following
command:ibm-clang++ -m32n-dll -c -Wall intMap.C
When you compile C++ code, use the ibm-clang++ invocation
command, which compiles the C++ code with the correct option defaults for
C++.To compile for DLLs under non-XPLINK compilation mode, specify -m32n-dll.
Under z/OS batch
Copy the source code examples validateArguments.c and intMap.C
into your data sets. For example, if your HLQ is PETE, store validateArguments.c in
PETE.TEST.C(VALIDARG) and intMap.C in PETE.TEST.CXX(INTMAP).
The source can be compiled as follows:
//COMP0 EXEC PROC=CLCC,
// INFILE='PETE.TEST.C(VALIDARG)',
// OUTFILE='PETE.TEST.OBJ(VALIDARG),DISP=SHR',
// CPARM='-Wall -mrent',
// LIBPRFX='<DEFAULT_LE_HLQ, CEE in most cases>',
// LNGPRFX='<HLQ>.CNWV210',
// CLBPRFX='<DEFAULT_LE_HLQ, CEE in most cases>'
//COMP1 EXEC PROC=CNWC,
// INFILE='PETE.TEST.CXX(INTMAP)',
// OUTFILE='PETE.TEST.OBJ(INTMAP),DISP=SHR',
// CPARM='-Wall',
// LIBPRFX='<DEFAULT_LE_HLQ, CEE in most cases>',
// LNGPRFX='<HLQ>.CNWV210',
// CLBPRFX='<DEFAULT_LE_HLQ, CEE in most cases>'
In step COMP0, the IBM-supplied cataloged procedure CLCC compiles the C source code under 32-bit non-XPLINK compilation mode. Compiler options are specified in the CPARM parameter. The -Wall compiler option enables warning of possible code issues. The -mrent option enables the compiler to take code that is not naturally reentrant and make it reentrant.
In step COMP1, the IBM-supplied cataloged procedure CNWC is used when compiling C++ code under 32-bit non-XPLINK compilation mode. This compiles the C++ code with the correct option defaults for C++.
You can use the SYSOUT DD statement to display compiler error messages.