twolink

Option Type Default Value #pragma options C C++
-flag notwolink* -   x

Syntax

-qtwolink | -qnotwolink

Purpose
Minimizes the number of static constructors included from libraries.

Notes
Normally, the compiler links in all static constructors defined anywhere in the object (.o) files and library (.a) files. The -qtwolink option makes link time take longer, but linking is compatible with older versions of C or C++ compilers.

Before using -qtwolink, make sure that any .o files placed in an archive do not change the behavior of the program.

Default
The default is notwolink. All static constructors in .o files and object files are invoked. This generates larger executable files, but ensures that placing a .o file in a library does not change the behavior of a program.

Example
Given the include file foo.h:

#include <stdio.h>
struct foo {
    foo() {printf ("in foo\n");}
    ~foo() {printf ("in ~foo\n");}
}; 

and the C++ program t.C:

#include "foo.h"
foo bar;

and the program t2.C:

#include "foo.h"
main() { }

Compile t.Cc and t2.C in two steps, first invoking the compiler to produce object files:

xlC -c t.C t2.C

and then link them to produce the executable file a.out:

xlC t.o t2.o

Invoking a.out produces:

in foo
in ~foo

If you use the AIX ar command with the t.o file to produce an archive file t.a:

ar rv t.a t.o

and then use the default compiler command:

xlC t2.o t.a

The output from the executable file is the same as above:

in foo
in ~foo

However, if you use the -qtwolink option:

xlC -qtwolink t2.o t.a

there is no output from the executable file a.out becuase the static constructor foo() in t.C is not found.



List of Batch Compiler Options and Their Defaults
Equivalent Batch Compile-Link and Incremental Build Options