Oracle® Solaris Studio 12.4: C++ User's Guide

Exit Print View

Updated: March 2015
 
 

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

  • If you compile with the -library or -m64/-m32 options, you must include these same options on all CC commands.

  • If you compile with -compat or -std options, you must include the same or equivalent options on all CC commands. For example, -compat=5 and -std=sun03 are equivalent.

  • With -p, -xpg, and -xprofile, including the option in one phase and excluding it from the other phase will not affect the correctness of the program, but you will not be able to do profiling.

  • With -g[n] and -xdebuginfo, including the option in one phase and excluding it from the other phase will not affect the correctness of the program, but it will affect the ability to debug the program. Any module that is not compiled with either of these options but is linked with -g[n] or -xdebuginfo will not be prepared properly for debugging. Note that compiling the module that contains the function main with the –g[n] option or the -xdebuginfo option is usually necessary for debugging.

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 default 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, some templates might 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.