C++ only


Minimizes the number of static constructors included from libraries and object files.


Read syntax diagramSkip visual syntax diagram        .-notwolink-.
>>- -q--+-twolink---+------------------------------------------><


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 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.


The default is -qnotwolink. 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.


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.C 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 because the static constructor foo() in t.C is not found.

Related information