Compiling IBM MQ sample programs on AIX platform using XL C/C++ Compiler
Prema Laxmanachar 270005MHW8 Comments (4) Visits (2503)
IBM recently announced support for XL C/C++ 13.1 on AIX. XL compiler is used to compile the IBM MQ samples like amqsput, amqsget and amqsbcg to put , get , browse samples using both client and server libraries. This document is helps for the user who wants to build their own 32 bit or 64bit applications using IBM MQ to put and get messages.
This document includes the information on XLC compiler, support AIX OS, how to find out the PATH and version of XL compiler installed and setting up the PATH of XL, installation of MQ, PATH of the C/CPP MQ samples, modes of compilation and commands to compile the samples using threaded and unthreaded modes.
You can find the more details in the below mentioned link
bash-4.2$ which xlC
Set PATH of the XL compiler as below if the PATH is not set. User might get warning like “xlc” not found when they issue xlc command.
# export PATH
Check the xlc version by passing the below commands
bash-4.2$ xlC -qversion=verbose
IBM XL C/C++ for AIX, V13.1 (5725-C72, 5765-J07)
Driver Version: 13.01(C/C++) Level: 140415 ID: _9iE
C Front End Version: 13.01(C/C++) Level: 140416 ID: _8DF
C++ Front End Version: 13.01(C/C++) Level: 140416 ID: _GH6
High-Level Optimizer Version: 13.01(C/C++) and 15.01(Fortran) Level: 140424 ID: _l_3
Low-Level Optimizer Version: 13.01(C/C++) and 15.01(Fortran) Level: 140424 ID: _mH4
IBM MQ will be installed by default on /usr/mqm directory.
Issue dspmqver to get the version of the MQ
Name: WebSphere MQ
BuildType: IKAP - (Production)
Platform: WebSphere MQ for AIX
O/S: AIX 6.1
If the user is new to IBM MQ, for installation you can follow the below link to install the MQ on AIX
Threaded Mode A thread is considered to be connected to IBM® MQ from MQCONN (or MQCONNX) until MQDISC. UNIX and Linux systems safely allow the setting up of a signal handler for such signals for the whole process. However, IBM MQ sets up its own handler for the following signals, in the application process, while any thread is connected to IBM MQ:
For more information on Threaded mode, refer the below mentioned link
Unthreaded Mode: All applications are considered threaded even if they use only a single thread.
Each MQI function sets up its own signal handler for the signals:
For more information on Unthreaded mode, refer the below mentioned link. http
Threaded and Unthreaded mode has 32 bit mode and 64 bit mode of compilation.
If you are compiling for 32 bit applications use 32 bit libraries to compile the samples whereas for 64 bit applications use 64 bit libraries to compile the samples. Below mentioned are the modes used to compile the samples on server and client.
One more important thing while compiling you should not use threaded and a non-threaded library at the same time, if used then it might cause the compilation failure.
Server Unthreaded 32 bi
Server Unthreaded 64 bit
Server Threaded 32 bit
Server Threaded 64 bit
Client Unthreaded 32 bit
Client Unthreaded 64 bit
Client Threaded 32 bit
Client Threaded 64 bit
For more information on compilation modes on AIX, refer the blow link. http
Precompiled C programs are supplied in the MQINST-dir/samp/bin directory. Below mentioned C/CPP samples present under MQINST-dir /samp directory.
amqsput0.c : amqsput sample program to put a message on the queue
amqsget0.c : amqsget sample program to get the message back from the queue
amqsbcg0.c : The Browser sample program reads and writes both the message descriptor and the message content fields of all the messages on a queue
imqsput.cpp : imqsput sample program to put a message on the queue
imqsget.cpp : imqsget sample program to get the message back from the queue
imqdput.cpp : imqdput sample program puts messages to a distribution list consisting of two queues.
imqwrld.cpp : imqwrld sample program shows how to put and get a regular datagram (C structure) using the ImqMessage class
Example that explains the command used for compiling 32 bit and 64 bit amqsput.c sample using threaded mode.
For 32–bit applications:
$ xlc_r -o amqsput_32_r amqsput0.c -I/MQINST-dir/inc -L/MQINST-dir/lib -lmqm_r
Xlc_r / xlC – Compiler command
-o amqsput_32_r : It is the output file of the compiled sample
amqsput0.c : amqsput sample C program
-I /MQINST-dir/inc – This refers to the C/CPP include files
-L /MQINST-dir/lib : This referes to the 32 bit library Path to link the 32 bit library file.
For 64–bit applications:
$ xlc_r -q64 -o amqsput_64_r amqsput0.c -I/MQINST-dir/inc -L/MQINST-dir/lib64 -lmqm_r
-o amqsput_64_r : output name is saved as 64 bit (you can choose your own output name of your choice)
-L/MQINST-dir/lib64 : This referes to the 64 bit library Path to link the 64 bit library file.
Note: If you compile for unthreaded application use “lmqm” library, whereas for threaded application use “lmqm_r” library to link.
If you want to use the programs on a machine that has only the WebSphere MQ client for AIX® installed, recompile the programs to link them with the client library (-lmqic)
Please refer the below mentioned link for detailed explanation:
Below are the commands used for compiling C/CPP samples in Threaded and Unthreaded mode on server and client.
Server 32 bit : - Unthreaded:
Compiling cpp samples:
xlC -o imqsput_32 imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqs23ia -limqb23ia -lmqm
xlC -o imqsget_32 imqsget.cpp -qchars=signed -I /MQinst-dir qm/inc -L /MQinst-dir /lib -limqs23ia -limqb23ia -lmqm
Compiling "c" samples:
xlC -o amqsput_32 amqsput0.c -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqs23ia -limqb23ia -lmqm
Server 32 bit - Threaded :
Compiling cpp samples:
xlC_r -o imqsput_32_r imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqs23ia_r -limqb23ia_r -lmqm_r
Compiling "c" samples:
xlC_r -o amqsput_32_r amqsput0.c -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqs23ia_r -limqb23ia_r -lmqm_r
Server 64 bit : - Unthreaded:
xlC -q64 -o imqsput_64 imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqs23ia -limqb23ia -lmqm
xlC -q64 -o imqsget_64 imqsget.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqs23ia -limqb23ia -lmqm
Server 64 bit Threaded :
xlC_r -q64 -o imqsput_64_r imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqs23ia_r -limqb23ia_r -lmqm_r
xlC_r -q64 -o imqsget_64_r imqsget.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqs23ia_r -limqb23ia_r -lmqm_r
Client mode :-
Client 32 bit Unthreaded:
xlC -o imqsputc_32 imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqc23ia -limqb23ia -lmqic
xlC -o imqsgetc_32 imqsget.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqc23ia -limqb23ia -lmqic
Client 32 bit threaded:
xlC_r -o imqsputc_32_r imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqc23ia_r -limqb23ia_r -lmqic_r
xlC_r -o imqsgetc_32_r imqsget.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib -limqc23ia_r -limqb23ia_r -lmqic_r
Client 64 bit unthreaded:
xlC -q64 -o imqsputc_64 imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqc23ia -limqb23ia -lmqic
xlC -q64 -o imqsgetc_64 imqsget.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqc23ia -limqb23ia -lmqic
Client 64 bit Threaded:
xlC_r -q64 -o imqsputc_64_r imqsput.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqc23ia_r -limqb23ia_r -lmqic_r
xlC_r -q64 -o imqsgetc_64_r imqsget.cpp -qchars=signed -I /MQinst-dir/inc -L /MQinst-dir/lib64 -limqc23ia_r -limqb23ia_r -lmqic_r
Note: -qchars=signed this parameter is applicable only for xl compiler 12 , 13 and above.
Make sure that while compiling or after compilation it should not throw any error message or warnings.
The error or warnings might notice during compilation are:
define ql(Q) defpsist(yes)
define chlannel(Channel name) chltype(svrconn) trptype(tcp) sslcauth(optional) mcauser('username ')
When trying to connect to the queue manager in the client mode using the compiled c/cpp samples, User needs to modify some security changes in Queue manager objects. Please refer the below given link to do the changes
Start the Listener : runmqlsr -t tcp -m QM -p 5656 &
After changing the properties, user can able to do the put and get using the compiled c/cpp samples. Go to the directory where the output of the compiled c/cpp samples are present. Using those samples user can easily put and get the messages
#./amqsput_32 Q QM
Sample AMQSPUT0 Start
target queue is Q
#./amqsget_32 Q QM
Sample AMQSGET0 Start
message <Test message>
#Likewise you can put and get messages using other compiled samples.
Below is the attached snapshot for the put and get messages using compiled samples
Generally errors like mqrc 2035 error (This error will generally appear when client tries to connect to the queue manager running on the machine) when user tries to put or get the messages to the queue. To overcome this problem, need to modify the Queue manager objects as mentioned above in step 7.
In system / queue manager error logs usually gets the error something like :
----- amqccita.c : 4116 ----
The AMQERR01.LOG shows that an application ended without a clean disconnect. This kind of error might occur when compilation of sample is in process and user terminated the samples before it had exited, which would be sufficient to cause this error in the log.
If we expect the application to exit cleanly, it should be rerun and given time to do so, in order to check that it does not hang indefinitely.
Note: While compilation of samples is in process, don’t terminate until unless it exit after completing the compilation.