Preparing C programs in AIX
Prepare and compile C programs in AIX by using the IBM® XL C/C++ compiler or the VisualAge® C/C++ compiler.
Before you begin
In the following code examples, ${MQ_INSTALLATION_PATH} represents the high-level
directory in which IBM MQ is installed. You can either
use the code unchanged, to pull in the value that you have set for variable ${MQ_INSTALLATION_PATH}, or you can replace
${MQ_INSTALLATION_PATH} with the actual
path.
You need to link your program with one of the following library files:
| Library file | Program/exit type |
|---|---|
| libmqm.a | Server for C (unthreaded application) |
| libmqm_r.a | Server for C (threaded application) |
| libmqic.a & libmqm.a | Client for C (unthreaded application) |
| libmqic_r.a & libmqm_r.a | Client for C (threaded application) |
- You cannot link to more than one library. That is, you cannot link to both a threaded and a non-threaded library at the same time.
- If you are writing an installable service (see the Administering IBM MQ for further information), you need to link to the libmqmzf.a library in a non-threaded application and to the libmqmzf_r.a library in a threaded application.
- If you are producing an application for external coordination by an XA-compliant transaction manager such as IBM TXSeries®, Encina, or BEA Tuxedo, you need to link to the libmqmxa.a (or libmqmxa64.a if your transaction manager treats the 'long' type as 64 bit) and libmqz.a libraries in a non-threaded application and to the libmqmxa_r.a (or libmqmxa64_r.a ) and libmqz_r.a libraries in a threaded application.
- You need to link trusted applications to the threaded IBM MQ libraries. However, only one thread in a trusted application on IBM MQ for AIX® or Linux® systems can be connected at a time.
- You must link IBM MQ libraries before any other product libraries.
About this task
Sample C programs are supplied in the ${MQ_INSTALLATION_PATH}/samp/bin directory.
Each of the following code examples uses the amqsput0 sample program with the XL
C/C++ compiler, and links with one of the Server for C library files. If you want to use the program
on a machine that has only the IBM MQ MQI client for AIX installed,
alter the example code to link with one of the client library (-lmqic) files
instead.
If you are using the VisualAge C/C++ compiler for
C++ programs, include the option -q namemangling=v5 to get all the IBM MQ symbols resolved when linking the libraries.
For more information about writing 64-bit applications, see Coding standards on 64-bit platforms.
Example
To compile a sample C program from a single compilation unit, run the appropriate command from the following list. These command examples use the IBM XL C/C++ for AIX compiler.
![[Deprecated]](ngdeprecated.gif)
Support for the XL C/C++ for AIX 16 compiler was deprecated in IBM MQ 9.4.0 (for Long Term Support releases, and IBM MQ 9.3.5 for
Continuous Delivery releases). This compiler was superseded by
the IBM Open XL C/C++ for AIX 17 compiler.
![[Removed]](ngremoved.gif)
The XL C/C++ for AIX 16 compiler was removed in IBM MQ 9.4.2.
These command examples use the IBM Open XL C/C++ for AIX 17 compiler:
32 bit non-threaded application-
ibm-clang -o amqsput_32 amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib -lmqm
32 bit threaded application-
ibm-clang_r -o amqsput_32_r amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib -lmqm_r
64 bit non-threaded application-
ibm-clang -m64 -o amqsput_64 amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib64 -lmqm
64 bit threaded application-
ibm-clang_r -m64 -o amqsput_64_r amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib64 -lmqm_r
- 32 bit non-threaded application
-
xlc -o amqsput_32 amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib -lmqm - 32 bit threaded application
-
xlc_r -o amqsputc_32_r amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib -lmqm_r - 64 bit non-threaded application
-
xlc -q64 -o amqsput_64 amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib64 -lmqm - 64 bit threaded application
-
xlc_r -q64 -o amqsputc_64_r amqsput0.c -I${MQ_INSTALLATION_PATH}/inc -L${MQ_INSTALLATION_PATH}/lib64 -lmqm_r