Linker Options

Options for linking.

Dynamic vs Static Linking

The linker is used to combine compiled object files and objects in libraries to form executable programs. There are two basic linking methods: dynamic and static.

With dynamic linking, the linker combines the explicitly specified object files and the library code that is not available in shared libraries into a single executable file. Library code that is available in shared libraries on the system is accessed at execution time by attaching to the shared libraries when and as needed.

With static linking, non-shared libraries are used to resolve external references where possible and those library objects are combined with the explicitly specified object files to form the executable file. Using static linking typically results in a larger executable file.

Beginning with CCE 9.0, the default linking method is dynamic. The choice of dynamic or static linking can be specified using the arguments -static or -dynamic on the ftn command line that is used for linking. (See the ftn(1) man page.) The options described in this section, -h dynamic or -h static, can also be used, but ftn -static or ftn -dynamic are the preferred and recommended methods. If neither is specified, CCE defaults to dynamic linking.

-h system_alloc, -h tcmalloc

This option specifies the malloc implementation to be used. This is a link-time option. On Cray XC systems, -h system_alloc is used by default when statically linking and -h tcmalloc is used by default when dynamically linking.

In the CCS environment, -h system_alloc is default and -h tcmalloc is not supported.

-h [no]pgas_runtime

Default: pgas_runtime

The -h pgas_runtime option directs the compiler driver to link with the runtime libraries required when linking programs that use UPC, or coarrays. In general, a resource manager job launcher such as aprun or srun must be used to launch the resulting executable.

The -hnopgas_runtime option prevents this runtime library environment from being added to the link line.

Use the -hnopgas_runtime option with a program that does not use native SPMD parallelism when it needs to be executed outside of the aprun/srun job launch context; for example, to test a serial program that does not contain such code on a login or service node, or fork/exec an executable on a compute node. Also, compile non-coarray Fortran using the -hnocaf option.

-l libname

The -l libname option directs the compiler driver to search for the specified object library file when linking an executable file. To request more than one library file, specify multiple -l options.

When statically linking, the compiler driver searches for libraries by prepending ldir/lib to libname and appending .a, for each ldir that has been specified by using the -L option. It uses the first file it finds.

When dynamically linking, the library search process is similar to the static case, with a few differences. The compiler driver searches for libraries by prepending ldir/lib on the front of libname and appending .so on the end of it, for each ldir that has been specified by using the -L option. If a matching .so is not found, the compiler driver replaces .so with .a and repeats the process from the beginning. It uses the first file it finds.

There is no search order dependency for libraries.

If personal libraries are specified by using the -l command line option, those libraries are added before the default CCE library list. The -l option is passed to the linker. For example, when the following command line is issued, the linker looks for a library named libmylib.a and adds it to the top of the list of default libraries.

cc -l mylib target.c

-L ldir

Changes the -l option search algorithm to look for library files in directory ldir during link time. To request more than one library directory, specify multiple -L options.

The linker searches for library files in the compiler release-specific directories.

Multiple -L options are treated cumulatively, as if all ldir arguments appear on -L options preceding all -l options. Therefore, do not attempt to link functions of the same name from different libraries through the use of alternating -L and -l options.

-o outfile

Produces an absolute binary file named outfile. A file named a.out is produced by default. When this option is used in conjunction with the -c option and a single source file, a relocatable object file named outfile is produced.