Section 5.3. Compilers

5.3. Compilers

IBM VisualAge XL C/C++ and GNU GCC/G++ both are ISO/ANSI standard-compliant, although XL claims to provide a higher level of compliance. In most cases, however, with the exception of a few warnings, applications built with XL C/C++ compile and link with GNU GCC/G++ with minimal effort. In its simplest form, the following syntax shows the similarity in compiler invocation under IBM and GNU. Here's your typical "Hello World" source compiled and linked with both XL and GNU compilers.

C compile and link


#include <stdio.h> int main() { printf("Hello World\n"); return 0; } 


gcc -c main.c -o main.o (GNU) xlc -c main.c o main.o (IBM/AIX) 


gcc -o main main.o (GNU) xlc -o main main.o (IBM/AIX) 

C++ compile and link


[View full width]

#include <iostream.h> int main() { cout << "Hello World\n" return 0; } g++ -c main.cpp -o main.o (GNU)[8] xlC -c main.cpp -o main.o (IBM/AIX)

[8] Under AIX, this syntax creates a deprecation warning for iostream.h that can be ignored for this source. To suppress this warning, use Wno-deprecated.


g++ -o main main.o (GNU) xlC -o main main.o (IBM/AIX) 

As you can see, the only difference between IBM XL C/C++ and GNU GCC/G++ is the invocation method between the C and C++ compile and link stage. For applications migrating from IBM environments, the equivalent C/C++ invocation under GNU is gcc/g++, respectively.

However, some migrations are not so straightforward. There are differences. The extent of those differences depends on the type of output you are trying to build, the code being ported, how well the original developers adhered to ANSI standards, and the number of dependent environment APIs used inside the application being ported.

5.3.1. Invoking the Compiler

One of the many features that IBM tried to build into their compiler is ease of use. Long ago, they recognized that developers used the same distinct parameters to build certain applications. For instance, in AIX, to build a multithreaded application, you must include the POSIX threads system library in your executable (libpthread). The same holds true for standard AIX system calls such as streams and file manipulations; developers must include the standard system library (libc.a) or some variant thereof.

To ease the complexity of trying to remember all the different required parameters and libraries to include when invoking their compiler, IBM introduced distinct compiler invocation methods that in turn turned on certain parameters and included distinct libraries automatically depending on the desired output. For instance, to build a multithreaded C application, the developer merely would have to invoke the xlc_r compiler method. The _r denotes REENTRANT, meaning the resulting executable will be thread-safe. When invoked on the compile line, this method automatically turns the following parameters on and includes the following libraries:

xlc_r: use = DEFLT   crt = /lib/crt0.o   mcrt = /lib/mcrt0.o   gcrt = /lib/gcrt0.o   libraries = -L/usr/lpp/xlopt,-lxlopt,-L/usr/lib/threads,-lpthreads, -lc   proflibs = -L/lib/profiled,-L/usr/lib/profiled   hdlibs = -L/usr/vac/lib,-lhmd_r   options = -qansialias,-qthreaded,-D_THREAD_SAFE,-D__VACPP_MULTI__ 

The preceding stanza is equivalent to the following ANSI C compiler invocation:[9]

[9] For a listing of all the XL C/C++ compiler invocations and the libraries and parameters that are automatically included, refer to the /etc/vac.cfg file on your AIX system.

cc -o <your desired output > -qansialias,-qthreaded,-D_THREAD_SAFE, -D__VACPP_MULTI__ -L/usr/lpp/xlopt -L/usr/lib/threads -L/lib/profiled -L/usr/lib/profiled -L/usr/vac/lib lxlopt lpthreads lc lhmd_r /lib/crt0.o /lib/mrt0.o /lib/gcrt0.o <your source   …> 

GNU GCC/G++ does not provide for this type of shorthand method in building certain types of applications. Depending on your desired output, you must include the appropriate library(s) and parameter(s) on the command line. For instance, the equivalent command in Linux that will replace the IBM XL C xlc_r method is as follows:

gcc -o <your desired output> -L/usr/lib lpthreads D_REENTRANT <your source …> 

Table 5-2 provides a GNU reference for each IBM XL C/C++ compiler invocation.

Table 5-2. Compiler Invocation on AIX and Linux

IBM XL C/C++ 5.0 or higher



xlc_r, cc_r, or (+ _r4, _r7)

gcc L/usr/lib/threads -lpthread -D_REENTRANT

POSIX 1003.1c threads

_r4 = DCE threads

xlC_r or (+ _r4, _r7)

g++ L/usr/lib/threads -lpthread -D_REENTRANT

_r7 = Provided by IBM for AIX 4.3 users to help with migration to POSIX Draft 10



ANSI C compiler usage




gcc ansi

Strict ANSI C standard (ISO/IEC 9899:1990)

xlc128 xlc128 cc128

Not supported

For XL C/C++ increases the length of long double types from 64 to 128 bits

For POSIX threads, depending on the current distribution of Linux you are porting to, additional preprocessor directives may need to be turned on. Refer to the document that came with your distribution.

Both IBM and GCC provide an array of compiler switches that enable the user to control the behavior and the type of output generated. For instance, both have optimization parameters to control the size and performance characteristics of an output, as well as switches to control how the executable is built, such as L and I switches, which control the search path of libraries and include files. In addition, some switches are architecture-specific and are exclusive to either IBM XLC/C++ or GCC. Table 5-3 compares compiler switches between IBM XLC/C++ and gcc/g++. Because some of the qoption switches for IBM XLC/C++ are architecture-specific, a comparable GCC compiler switch is not available.

Table 5-3. XLC/C++ and gcc/g++ Compiler Switches Comparison Table

C/C++ VisualAge for AIX Option[10]

GNU gcc Option[11]

Description (AIX-based)


-x c++

(C++) Compiles any file, filename.nnn, as a C++ language file, where nnn is any suffix other than .o, .a, or .s.



Traces the compilation without doing anything.

-q32 -q64

-m32[12] -m64[12]

Selects 32- or 64-bit compiler mode. Additional m options for GCC are available. Refer to GNU Documentation Online.



Specifies which language level to use when invoking the compiler.



Enables destructive copy operations for structures and unions.

-qalias -qansialias


Specifies which type-based aliasing is to be used during optimization.



Specifies what aggregate alignment rules the compiler uses for file compilation.

-qalloca -ma


Substitutes inline code for calls to function alloca as if #pragma alloca directives are in the source code.



Specifies the type of IBM architecture on which the executable program will be run. This refers to all the RS6000 and POWER architectures.



Asks the compiler to apply aliasing assertions to your compilation unit.



Produces a compiler listing that includes an attribute listing for all identifiers.

B, t


-B: Determines substitute path names for the compiler, assembler, linkage editor, and preprocessor. -t: Adds the prefix specified by the -B option to designated programs. -tE replaces the CreateExportList script.

-bdynamic -bshared

-shared fpic (or fPIC) -Bsharable or -Wl brt -shared

Instructs the linker to process subsequent shared objects as either dynamic or shared.


-static -Bstatic -dn -non-shared

Links all referenced objects statically although they may be shared objects.


-fsigned-bitfields (default)

Specifies whether bitfields are signed.


Refer to the section, "Large Page Support," in Chapter 3.

Sets the size of the heap in bytes.


-shared -wl Refer Section 5.5, "Linker."

Enables runtime linking.



Preserves comments in preprocessed output.



Instructs the compiler to pass source files to the compiler only.



Specifies a cache configuration for a specific execution machine.

-qchars=[signed or unsigned]

-fsigned-char funsigned-char

Instructs the compiler to treat all variables of type char as either signed or unsigned.



Generates code that performs certain types of runtime checking



(C++) Includes files from specified directories have the tokens extern " C " { inserted before the file, and } appended after the file.



When used with optimization, reduces code size where possible, at the expense of execution speed.


C++ syle of comments is turned on automatically in GNU C, unless ansi is turned on.

(C++) Use this option if you want C++ comments to be recognized in C source files.



Defines the identifier name, as in a #define preprocessor directive.



Marks data as imported. Used to import functions.



Marks data as local.



(C only) Specifies that all typedef declarations, struct, union, and enum type definitions are included for debugger processing.



Allows use of digraph character sequences in your program.


fdollars-in-identifiers This is the default behavior of GNU on most platforms.

Allows the $ symbol to be used in the names of identifiers.



Generates block scopes to support the IBM Dynamic Probe Class Library.



Runs the source files named in the compiler invocation through the preprocessor.


-e Label --entry=Label Refer to the "Linker" section.

Specifies the entry name for the shared object. Equivalent to using ld -e name. See your system documentation for additional information about ld options. Used only with qmkshrobj.



(C++) Controls exception handling.


Use keyword __attribute__[13]

Specifies the amount of storage occupied by the enumerations.



Saves all exported symbols in a file.



Generates bind-time type of checking information and checks for compile-time consistency.



Names an alternative configuration file for xlC.



Names a file to store a list of object files.



Collects program information for use with the AIX fdpr performance-tuning utility.



Specifies the minimum severity level of diagnostic messages to be reported.


None (Accuracy of floating-point is different on differing platforms.)

Specifies various floating-point options to speed up or improve the accuracy of floating-point operations.


-mfp-trap-mode= TRap mode

Generates extra instructions to detect and trap floating-point exceptions.



Specifies that constant floating-point expressions are to be evaluated at compile time.



Specifies what path information is stored for files when you use -g and the distributed graphical debugger.



Places instructions for each function in a separate object file, control section, or csect.


-shared Bshareable

Linkage editor (ld command) option only. Used to generate a dynamic libary file.



Generates debugging information used by a debugger such as the Distributed Debugger.



Produces ANSI prototypes from K&R function definitions.



Instructs the compiler to stop after the compilation phase when it encounters errors of specified severity or greater.



Enables debug versions of memory management functions.



Instructs the compiler to perform high-order transformations on loops and array language during optimization, and to pad array dimensions and data objects to avoid cache misses.



Speeds up calculations by removing range checking on single-precision float results and on conversions from floating-point to integer.



Specifies that single-precision expressions are rounded only when the results are stored into float memory locations.



Specifies an additional search path if the filename in the #include directive is not specified using its absolute path name.



Specifies the search order for files included with the #include file_name directive.



Allows the compiler to perform optimizations that assume errno is not modified by system calls.



Instructs the compiler to ignore certain pragma statements.



Produces informational messages.



Initializes automatic storage to a specified two-digit hexadecimal byte value.



Generates fast external linkage by inlining the pointer glue code necessary to make a call to an external function or a call through a function pointer.



Attempts to inline functions instead of generating calls to a function.



Turns on or customizes a class of optimizations known as interprocedural analysis (IPA).



Specifies functions in the source file that have no side effects.



(C++) Instructs the compiler to keep or discard definitions for unreferenced extern inline functions.



Controls whether a specified string is treated as a keyword or an identifier.



Searches the specified directory for library files specified by the -l option.



Searches a specified library for linking.


-ansi flang-isoc9x

Selects the C or C++ language level for compilation.


Refer to the "Large Page Support," section.

Instructs the compiler to exploit large page heaps available on Power4 systems running AIX v5.1D or later.

-qldbl128, -qlongdouble


Increases the size of long double type from 64 bits to 128 bits.



Assumes that all functions with the name of an ANSI C library function are in fact the system functions.



Generates abbreviated line number and source filename information for the debugger.



Produces a compiler listing that includes an object listing.



Produces a compiler listing that displays all options in effect.



Makes unsuffixed literals the long type for 64-bit mode.


-mlong64 (Refer to the m options for your targeted platform.)

Allows long long types in your program.



Creates an output file that contains targets suitable for inclusion in a description file for the AIX make command.


Refer to alloc.

(C only) Substitutes inline code for calls to function alloca as if #pragma alloca directives are in the source code.



(C only) Converts Pascal string literals into null-terminated strings where the first byte contains the length of the string.



Specifies whether the floating-point multiply-add instructions are to be generated.



Creates an output file that contains targets suitable for inclusion in a description file for the AIX make command.



Instructs the compiler to halt compilation when a specified number of errors of specified or greater severity is reached.



Limits the amount of memory used for local tables of specific, memory-intensive optimizations.

-qmbcs dbcs


Use the -qmbcs option if your program contains multibyte characters.


-shared or libtool[15]

Creates a shared object from generated object files.



Selects the name-mangling scheme for external symbol names generated from C++ source code.

-O -qoptimize


Optimizes code at a choice of levels during compilation.



Specifies a name or directory for the output executable file(s) created either by the compiler or the linkage editor.



(C++) Sets the type of object model.



(C++) Specifies how classes containing const or reference members are passed in function arguments.



Preprocesses the C or C++ source files named in the compiler invocation and creates an output preprocessed source file for each input source file.



Sets up the object files produced by the compiler for profiling.



(C only) Ignores the word pascal in type specifiers and function declarations.



Constructs alternate program and path names.

-qpdf1 -qpdf2


Tunes optimizations through Profile-Directed Feedback.



Sets up the object files for profiling, but provides more information than is provided by the -p option.



Reports the time taken in each compilation phase.



Suppresses listings.



(C++) Specifies the priority level for the initialization of static constructors.

-qproclocal -qprocimported -qprocunknown


Marks functions as local, imported, or unknown.



(C only) Assumes all functions are prototyped.



Attempts to inline functions instead of generating calls to a function.



Produces a relocatable object.



Instructs the compiler to produce transformation reports that show how program loops are parallelized and optimized.



Controls the compile-time rounding mode of constant floating-point expressions.



Specifies that the result of each single-precision float operation is to be rounded to single precision.



Specifies the storage type for string literals.



Specifies the storage location for constant values.



Prevents floating-point optimizations that are incompatible with runtime rounding to plus and minus infinity modes.



(C++) Generates runtime type identification (RTTI) information for the typeid operator and the dynamic_cast operator.



Generates an assembly language file (.s) for each source file.



Strips the symbol table.



If used with -qsource, all the include files are included in the source listing.



Instructs the compiler to reduce the size of the stack frame.



Enables parallelization of IBM SMP-compliant program code.



Produces a compiler listing and includes source code.



Specifies the size of the register allocation spill area.



Generates extra instructions to detect signaling NaN on conversion from single precision to double precision.



(C only) Adds the corresponding source code lines to the diagnostic messages in the stderr file.



(C ++) Controls whether inline functions are treated as static or extern.



Adds user-defined, nonexternal names that have a persistent storage class to the name list.


-nostdinc (nostdinc++ for and C++ source )

Specifies which files are included with #include <file_name> and #include "file_name" directives.



Turns off aggressive optimizations of the -O3 option that have the potential to alter the semantics of your program.



Disables loop-induction variable optimizations that have the potential to alter the semantics of your program.



Specifies compiler message numbers to be suppressed.



Set symbol tables for unreferenced variables or xcoff objects.



(C only) Causes the compiler to perform syntax checking without generating an object file.



Changes the length of tabs as perceived by the compiler.



Sets traceback table characteristics.



(C++) Generates separate include files for template functions and class declarations, and places these files in a directory, which can be optionally specified.



(C ++) Helps manage dependencies between compilation units that have been compiled using the -qtemplateregistry compiler option.



(C++) Maintains records of all templates as they are encountered in the source and ensures that only one instantiation of each template is made.



(C++) Specifies the maximum number of template include files to be generated by the tempinc option for each header file.


-lpthread -D_REENTRANT

Indicates that the program will run in a multithreaded environment.



(C++) Controls whether parsing and semantic checking are applied to template definition implementations.



Marks data as local.



Enables TOC merging to reduce TOC pointer loads and improves the scheduling of external loads.



Specifies the architecture for which the executable program is optimized.



(C++) Minimizes the number of static constructors included from libraries.



Undefines a specified identifier defined by the compiler or by the -D option.



(C++) Generates unique names for static constructor/deconstructor file-compilation units.



Unrolls inner loops in the program.



Informs the compiler that the application does not rely on any program stack unwinding mechanism.



Preserves the unsigned specification when performing integral promotions.



Instructs the compiler to report information on the progress of the compilation in a command-like format.



Instructs the compiler to report information on the progress of the compilation.



(C++) Controls the generation of virtual function tables.



Passes the listed words to a designated compiler program.



Requests that warning messages be suppressed.



Enables warning of possible long to integer data truncations.



Generates code to static routines within a compilation unit as if they were external calls.



Produces a compiler listing that includes a cross-reference listing of all identifiers.



Specifies the compile-time rounding mode of constant floating-point expressions. See also rndflt.

[10] VisualAge C++ for AIX Compiler Reference (SC09-4959-00)

[11] GNU Compiler Collections version 3.4.2 (last updated May 23, 2004)

[12] These are all part of the GNU m machine-dependent options. Refer to the following link for specific platform compiler options:

[13] Refer to "Specifying Attributes of Types" in the GNU documentation:

[14] Part of GCC environment variables

[15] As an alternative, GNU Libtool could be used. Similar to the qmkshrobj option, Libtool is also a script, but it provides a generic interface for building platform-independent libraries. Refer to for more information about using it.

[16] gcov is a tool you can use in conjuction with GNU CC to test and profile code coverage. For more information about gcov, refer to the GNU documentation.

UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175 © 2008-2017.
If you may any questions please contact us: