Compiling your AIX source

You can install one of the AIX® compiler products that support installation on IBM® i to compile your programs in the PASE for i environment.

When your program uses AIX interfaces only, you can compile with any required AIX headers and link with AIX libraries to prepare binary files for PASE for i. Keep in mind that PASE for i does not support applications that are statically bound with AIX system-supplied shared libraries.

PASE for i programs are structurally identical to AIX programs for PowerPC®.

PASE for i (option 33 of the operating system) does not include a compiler. You use an AIX system to compile PASE for i programs, or you can optionally install one of the AIX compiler products that support installation in PASE for i to compile your programs in the PASE for i environment.

Using AIX compilers on the System p platform

You can build PASE for i programs using any AIX compiler and linker that generate output that is compatible with the AIX application binary interface (ABI) for PowerPC. PASE for i provides instruction emulation support for binary files that use POWER® architecture instructions that do not exist in PowerPC (except for IBM POWER instructions for cache management).

Using AIX compilers in PASE for i

IBM i supports the installation of the following separately available AIX compilers in the PASE for i environment:

  • IBM XL C/C++ for AIX
  • IBM XL C for AIX
  • IBM XL Fortran for AIX

Using these products, you can develop, compile, build, and run your PASE for i applications entirely within the PASE for i environment on your system.

Development tools

Many development tools that you use on AIX (for example, ld, ar, make, yacc) are included with PASE for i. Many AIX tools from other sources (for instance, the open-source tool gcc) can also work in PASE for i.

The IBM Tools for Developers for i5/OS PRPQ (5799-PTL) also contains a wide array of tools to help with the development, building, and porting of IBM i applications. For more information about this PRPQ, see the IBM Tools for Developers for i5/OS Web site.

Compiler notes for handling of pointers

  • The xlc compiler provides limited support for 16-byte alignment (for type long double) by using the combination of -qlngdbl128 and -qalign=natural. Type ILEpointer requires these compiler options to ensure that machine interface (MI) pointers are 16-byte aligned within structures. Using option -qldbl128 forces type long double to be a 128-bit type that requires use of libc128.a to handle operations like printf for long double fields.

    An easy way to get option -qlngdbl128 and link with libc128.a is to use the xlc128 command instead of the xlc command.

  • The xlc/xlC compiler currently does not provide a way to force 16-byte alignment for static or automatic variables. The compiler only guarantees relative alignment for 128-bit long double fields within structures. The PASE for i version of malloc always provides 16-byte aligned storage, and you can arrange 16-byte alignment of stack storage.
  • Header file as400_types.h also relies on type long long to be a 64-bit integer. xlc compiler option -qlonglong ensures this geometry (which is not the default for all commands that run the xlc compiler).

Examples

The following examples are intended for use when you are compiling your PASE for i programs on an AIX system. If you are using a compiler installed in PASE for i to compile your programs, you do not need to specify compiler options for the locations of IBM i system-unique header files or IBM i system-unique exports because these files will be found in their default path locations of /usr/include/ and /usr/lib/ on an IBM i system.

Example 1

The following command on an AIX system creates an PASE for i program named testpgm that can use IBM i system-unique interfaces exported by libc.a:

xlc -o testpgm -qldbl128 -qlonglong -qalign=natural
         -bI:/mydir/as400_libc.exp testpgm.c

This example assumes that the IBM i system-unique header files are copied to the AIX directory /usr/include and that the IBM i system-unique exports files are copied to the AIX directory /mydir.

Example 2

The following example assumes IBM i system-unique headers and export files are in /pase/lib:

xlc -o as400_test -qldbl128 -qlonglong -qalign=natural -H16
          -l c128
          -I /pase/lib
          -bI:/pase/lib/as400_libc.exp as400_test.c

Example 3

The following example builds the same program as example 2 with the same options; however, the xlc_r command is used for a multithreaded program to ensure that the compiled application links with threadsafe runtime libraries:

xlc_r -o as400_test -qldbl128 -qlonglong -qalign=natural -H16
            -l c128
            -I /pase/lib
            -bI:/pase/lib/as400_libc.exp as400_test.c

In the examples, if you are using PASE for i support for IBM DB2® for i call level interfaces (CLIs), you also need to specify -bI:/pase/include/libdb400.exp on your build command.

The -bI directive tells the compiler to pass the parameter to the ld command. The directive specifies an export file containing exported symbols from a library to be imported by the application.