Developer Guide and Reference

Contents

Passing Options to the Linker

Specifying 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.

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.
You can use the
Qoption
option 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(linker, "/defaultlib:mylib.lib")
OR
#pragma comment(lib, "mylib.lib")
Both examples instruct the compiler to link
mylib.lib
at link time.

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
-L
directory
Instruct the linker to search
directory
for libraries.
-Qoption
,tool,list