Building C++ programs on z/OS UNIX System Services

Build IBM MQ C++ programs on z/OS for Unix System Services.

To build an application under the UNIX System Services shell, we must give the compiler access to the IBM MQ include files (located in thlqual.SCSQC370 and hlqual.SCSQHPPS ), and link against two of the DLL sidedecks (located in thlqual.SCSQDEFS ). At runtime, the application needs access to the IBM MQ data sets thlqual.SCSQLOAD, thlqual.SCSQAUTH, and one of the language specific data sets, such as thlqual.SCSQANLE 1 .


Compiling

  1. Copy the sample into the file system using the TSO oput command, or use FTP. The rest of this example assumes that we have copied the sample into a directory called /u/fred/sample, and named it imqwrld.cpp.
  2. Log into the UNIX System Services shell, and change to the directory where you placed the sample.
  3. Set up the C++ compiler so that it can accept the DLL sidedeck and .cpp files as input:
    /u/fred/sample:> export _CXX_EXTRA_ARGS=1
    /u/fred/sample:> export _CXX_CXXSUFFIX="cpp"
    
  4. Compile and link the sample program. The following command links the program with the batch sidedecks; the RRS batch sidedecks can be used instead. The \ character is used to split the command over more than one line. Do not enter this character; enter the command as a single line:
    /u/fred/sample:> c++ -o imqwrld -I "//'thlqual.SCSQC370'" \
    -I "//'thlqual.SCSQHPPS'" imqwrld.cpp \
    "//'thlqual.SCSQDEFS(IMQS23DM)'" "//'thlqual.SCSQDEFS(IMQB23DM)'"
    

For more information on the TSO oput command, refer to the z/OS UNIX System Services Command Reference.

We can also use the make utility to simplify building C++ programs. Here is a sample makefile to build the HELLO WORLD C++ sample program. It separates the compiling and linking stages. Set up the environment as in step 3 before running make.

flags = -I "//'thlqual.SCSQC370'" -I "//'thlqual.SCSQHPPS'"
decks = "//'thlqual.SCSQDEFS(IMQS23DM)'" "//'thlqual.SCSQDEFS(IMQB23DM)'"

imqwrld: imqwrld.o
   c++ -o imqwrld imqwrld.o $(decks)

imqwrld.o: imqwrld.cpp
   c++ -c -o imqwrld $(flags) imqwrld.cpp

Refer to z/OS UNIX System Services Programming Tools for more information on using make.


Running

  1. Log into the UNIX System Services shell, and change to the directory where you built the sample.
  2. Set up the STEPLIB environment variable to include the IBM MQ data sets:
    /u/fred/sample:> export STEPLIB=$STEPLIB:thlqual.SCSQLOAD
    /u/fred/sample:> export STEPLIB=$STEPLIB:thlqual.SCSQAUTH
    /u/fred/sample:> export STEPLIB=$STEPLIB:thlqual.SCSQANLE
    
  3. Run the sample:
    /u/fred/sample:> ./imqwrld
    

Parent topic: Building IBM MQ C++ programs 1 We can link with any of the sidedecks listed in "Pre-link the object code to run your UNIX system service in any of the three environments, Building C++ programs on z/OS Batch, RRS Batch and CICS