Intel® C++ Compiler Classic Developer Guide and Reference

ID 767249
Date 12/16/2022
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.

Linux and macOS

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.

Windows

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

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

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

In this example, 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. The compiler does not recognize -delayload:comct132.dll, so the link option is used to direct the option to the linking phase. On C++, you can use the Qoption option to pass options to various tools, including the linker. You can also use #pragma comment on C++ to pass options to the linker. For example:

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

Both examples instruct the compiler to link mylib.lib at link time.