Sun Studio 12 Update 1: C++ User's Guide

2.4.3 Consistent Compiling and Linking

If you compile and link in separate steps, consistent compiling and linking is critical when using the compiler options listed in 3.3.3 Compile-Time and Link-Time Options.

If you compile a subprogram using any of these options, you must link using the same option as well:

In the following example, the programs are compiled using the -library=stlport4 compiler option.


 example% CC -library=stlport4 sbr.cc -c
example% CC -library=stlport4 main.cc -c
example% CC -library=stlport4 sbr.o main.o -o myprogram 

If you do not use -library=stlport4 consistently, some parts of the program will use the deafult libCstd, and others will use the optional replacement STlport library. The resulting program might not link, and would not in any case run correctly.

If the program uses templates, it is possible that some templates will get instantiated at link time. In that case the command line options from the last line (the link line) will be used to compile the instantiated templates.