Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Pass Options to the Linker

Specify Linker Options

This topic describes the options that let you control and customize linking with tools and libraries and define the output of the linker.

NOTE:

Starting with version 2024.0, options specified with the Clang -mllvm flag are no longer passed through to linker option processing. Instead, use the -Wl option to pass options to the linker. For example, to pass the -lto-debug-options option to the linker, use:

-Wl,-plugin-opt,-lto-debug-options

Linux

This section describes options specified at compile-time that take effect at link-time to define the output of the ld linker. See the ld man page for more information on the linker.

Option

Description

-Ldirectory

Instruct the linker to search directory for libraries.

-Qoption,tool,list

Passes an argument list to another program in the compilation sequence, such as the assembler or linker.

-shared

Instructs the compiler to build a Dynamic Shared Object (DSO) instead of an executable.

-shared-libgcc

-shared-libgcc has the opposite effect of -static-libgcc. When it is used, the GNU standard libraries are linked in dynamically, allowing the user to override the static linking behavior when the -static option is used.

NOTE:

Note: By default, all C++ standard and support libraries are linked dynamically.

-shared-intel

Specifies that all Intel-provided libraries should be linked dynamically.

-static

Causes the executable to link all libraries statically, as opposed to dynamically.

When -static is not used:

  • /lib/ld-linux.so.2 is linked in

  • all other libs are linked dynamically

When -static is used:
  • /lib/ld-linux.so.2 is not linked in

  • all other libs are linked statically

-static-libgcc

This option causes the GNU standard libraries to be linked in statically.

-static-intel

This option causes Intel-provided libraries to be linked in statically. It is the opposite of -shared-intel.

-Wl,optlist

This option passes a comma-separated list (optlist) of options to the linker.

-Xlinker val

This option passes a value (val), such as a linker option, an object, or a library, directly to the linker.

Windows

This section describes options specified at compile-time that take effect at link-time.

NOTE:

Linker options do not work for SYCL kernels, but they do work for host code (including pragmas for linker options).

You can use the link option to pass options specifically to the linker at compile time. For example:

icx a.cpp libfoo.lib /link -delayload:comct132.dll

The compiler recognizes that libfoo.lib is a library that should be linked with a.cpp, so it does not need to follow the link option on the command line.

However, the compiler does not recognize -delayload:comct132.dll, so the link option is used to direct the option to the linking phase:

#pragma comment(linker, "/defaultlib:mylib.lib")

On C++, you can use option Qoption to pass options to various tools, including the linker. You can also use #pragma comment to pass options to the linker. For example:

#pragma comment(lib, "mylib.lib")

Note that both the above #pragma examples instruct the compiler to link mylib.lib at link time.