链接器选项Linker Options

LINK.exe 将通用对象文件格式 (COFF) 对象文件和库链接起来,以创建可执行 (.exe) 文件或动态链接库 (DLL)。LINK.exe links Common Object File Format (COFF) object files and libraries to create an executable (.exe) file or a dynamic-link library (DLL).

下表列出了 LINK.exe 的选项。The following table lists options for LINK.exe. 有关 LINK 的详细信息,请参阅:For more information about LINK, see:

在命令行中,不区分大小写; 链接器选项例如,/base 和 /BASE 的含义相同的操作。On the command line, linker options are not case-sensitive; for example, /base and /BASE mean the same thing. 有关如何在命令行或 Visual Studio 中指定每个选项的详细信息,请参阅适用于该选项的文档。For details on how to specify each option on the command line or in Visual Studio, see the documentation for that option.

可以使用 注释 杂注指定一些链接器选项。You can use the comment pragma to specify some linker options.

选项Option 目标Purpose
@ 指定响应文件。Specifies a response file.
/ALIGN/ALIGN 指定每一节的对齐方式。Specifies the alignment of each section.
/ALLOWBIND/ALLOWBIND 指定 DLL 不能绑定。Specifies that a DLL cannot be bound.
/ALLOWISOLATION/ALLOWISOLATION 指定清单查找的行为。Specifies behavior for manifest lookup.
/APPCONTAINER/APPCONTAINER 指定应用是否必须在 appcontainer 进程环境中运行。Specifies whether the app must run within an appcontainer process environment.
/ASSEMBLYDEBUG/ASSEMBLYDEBUG DebuggableAttribute 添加到托管映像中。Adds the DebuggableAttribute to a managed image.
/ASSEMBLYLINKRESOURCE/ASSEMBLYLINKRESOURCE 创建指向托管资源的链接。Creates a link to a managed resource.
/ASSEMBLYMODULE/ASSEMBLYMODULE 指定应将 Microsoft 中间语言 (MSIL) 模块导入到程序集中。Specifies that a Microsoft intermediate language (MSIL) module should be imported into the assembly.
/ASSEMBLYRESOURCE/ASSEMBLYRESOURCE 将托管资源文件嵌入程序集。Embeds a managed resource file in an assembly.
/BASE/BASE 为程序设置基址。Sets a base address for the program.
/CGTHREADS/CGTHREADS 设置 cl.exe 线程数以在指定链接时代码生成后用于优化和代码生成。Sets number of cl.exe threads to use for optimization and code generation when link-time code generation is specified.
/CLRIMAGETYPE/CLRIMAGETYPE 设置 CLR 映像的类型(IJW、纯或安全)。Sets the type (IJW, pure, or safe) of a CLR image.
/CLRSUPPORTLASTERROR/CLRSUPPORTLASTERROR 保留通过 P/Invoke 机制调用的函数的上一个错误代码。Preserves the last error code of functions that are called through the P/Invoke mechanism.
/CLRTHREADATTRIBUTE/CLRTHREADATTRIBUTE 指定要应用于 CLR 程序入口点的线程特性。Specifies the threading attribute to apply to the entry point of your CLR program.
/CLRUNMANAGEDCODECHECK/CLRUNMANAGEDCODECHECK 指定链接器是否将 SuppressUnmanagedCodeSecurity 特性应用于链接器生成的、从托管代码调用到本机 DLL 中的 PInvoke 存根。Specifies whether the linker will apply the SuppressUnmanagedCodeSecurity attribute to linker-generated PInvoke stubs that call from managed code into native DLLs.
/DEBUG/DEBUG 创建调试信息。Creates debugging information.
/DEBUGTYPE/DEBUGTYPE 指定要包括在调试信息中的数据。Specifies which data to include in debugging information.
/DEF/DEF 将模块定义 (.def) 文件传递到链接器。Passes a module-definition (.def) file to the linker.
/DEFAULTLIB/DEFAULTLIB 在解析外部引用时搜索指定的库。Searches the specified library when external references are resolved.
/DELAY/DELAY 控制 DLL 的延迟加载。Controls the delayed loading of DLLs.
/DELAYLOAD/DELAYLOAD 导致延迟加载指定的 DLL。Causes the delayed loading of the specified DLL.
/DELAYSIGN/DELAYSIGN 对程序集进行部分签名。Partially signs an assembly.
/ DEPENDENTLOADFLAG/DEPENDENTLOADFLAG 设置依赖 DLL 加载默认标志。Sets default flags on dependent DLL loads.
/DLL/DLL 生成 DLL。Builds a DLL.
/DRIVER/DRIVER 创建内核模式驱动程序。Creates a kernel mode driver.
/DYNAMICBASE/DYNAMICBASE 使用地址空间布局随机化 (ASLR) 功能,指定是否生成可在加载时随机重新设定基址的可执行文件映像。Specifies whether to generate an executable image that can be randomly rebased at load time by using the address space layout randomization (ASLR) feature.
/ENTRY/ENTRY 设置起始地址。Sets the starting address.
/errorReport/errorReport 向 Microsoft 报告内部链接器错误。Reports internal linker errors to Microsoft.
/EXPORT/EXPORT 导出函数。Exports a function.
/FILEALIGN/FILEALIGN 对齐指定值的序列图上的输出文件中的部分。Aligns sections within the output file on multiples of a specified value.
/FIXED/FIXED 创建只能在其首选基址加载的程序。Creates a program that can be loaded only at its preferred base address.
/FORCE/FORCE 强制完成链接,即使符号无法解析或已定义多次。Forces a link to complete even with unresolved symbols or symbols defined more than once.
/FUNCTIONPADMIN/FUNCTIONPADMIN 创建可进行热修补的映像。Creates an image that can be hot patched.
/GENPROFILE、/FASTGENPROFILE/GENPROFILE, /FASTGENPROFILE 这两个选项均通过链接器指定 .pgd 文件的生成,以支持按配置文件优化 (PGO)。Both of these options specify generation of a .pgd file by the linker to support profile-guided optimization (PGO). /GENPROFILE 和 /FASTGENPROFILE 使用不同的默认参数。/GENPROFILE and /FASTGENPROFILE use different default parameters.
/GUARD/GUARD 启用控制流防护保护。Enables Control Flow Guard protection.
/HEAP/HEAP 设置堆的大小(以字节为单位)。Sets the size of the heap, in bytes.
/HIGHENTROPYVA/HIGHENTROPYVA 指定对高熵 64 位地址空间布局随机化 (ASLR) 的支持。Specifies support for high-entropy 64-bit address space layout randomization (ASLR).
/IDLOUT/IDLOUT 指定 .idl 文件和其他 MIDL 输出文件的名称。Specifies the name of the .idl file and other MIDL output files.
/IGNORE/IGNORE 禁止显示指定链接器警告的输出。Suppresses output of specified linker warnings.
/IGNOREIDL/IGNOREIDL 防止将特性信息处理到 .idl 文件中。Prevents the processing of attribute information into an .idl file.
/IMPLIB/IMPLIB 重写默认的导入库名。Overrides the default import library name.
/INCLUDE/INCLUDE 强制符号引用。Forces symbol references.
/INCREMENTAL/INCREMENTAL 控制增量链接。Controls incremental linking.
/INTEGRITYCHECK/INTEGRITYCHECK 指定模块需要在加载时进行签名检查。Specifies that the module requires a signature check at load time.
/KEYCONTAINER/KEYCONTAINER 指定用来对程序集进行签名的密钥容器。Specifies a key container to sign an assembly.
/KEYFILE/KEYFILE 指定用来对程序集进行签名的密钥或密钥对。Specifies a key or key pair to sign an assembly.
/LARGEADDRESSAWARE/LARGEADDRESSAWARE 通知编译器应用程序支持大于 2 GB 的地址Tells the compiler that the application supports addresses larger than two gigabytes
/LIBPATH/LIBPATH 指定要在环境库路径之前搜索的路径。Specifies a path to search before the environmental library path.
/LTCG/LTCG 指定链接时间代码生成。Specifies link-time code generation.
/MACHINE/MACHINE 指定目标平台。Specifies the target platform.
/MANIFEST/MANIFEST 创建并行清单文件,也可以选择将其嵌入二进制文件。Creates a side-by-side manifest file and optionally embeds it in the binary.
/MANIFESTDEPENDENCY/MANIFESTDEPENDENCY 指定<dependentAssembly > 清单文件中的部分。Specifies a <dependentAssembly> section in the manifest file.
/MANIFESTFILE/MANIFESTFILE 更改清单文件的默认名称。Changes the default name of the manifest file.
/MANIFESTINPUT/MANIFESTINPUT 指定链接器要进行处理并嵌入二进制文件的清单输入文件。Specifies a manifest input file for the linker to process and embed in the binary. 可以多次使用此选项以指定多个清单输入文件。You can use this option multiple times to specify more than one manifest input file.
/MANIFESTUAC/MANIFESTUAC 指定是否将用户帐户控制 (UAC) 信息嵌入到程序清单中。Specifies whether User Account Control (UAC) information is embedded in the program manifest.
/MAP/MAP 创建映射文件。Creates a mapfile.
/MAPINFO/MAPINFO 包括映射文件中的指定信息。Includes the specified information in the mapfile.
/MERGE/MERGE 合并节。Combines sections.
/MIDL/MIDL 指定 MIDL 命令行选项。Specifies MIDL command-line options.
/ NATVIS/NATVIS 将调试器可视化工具中的 Natvis 文件添加到 PDB。Adds debugger visualizers from a Natvis file to the PDB.
/NOASSEMBLY/NOASSEMBLY 取消创建 .NET Framework 程序集。Suppresses the creation of a .NET Framework assembly.
/NODEFAULTLIB/NODEFAULTLIB 在解析外部引用时忽略所有(或指定的)默认库。Ignores all (or the specified) default libraries when external references are resolved.
/NOENTRY/NOENTRY 创建纯资源 DLL。Creates a resource-only DLL.
/NOLOGO/NOLOGO 取消显示启动版权标志。Suppresses the startup banner.
/NXCOMPAT/NXCOMPAT 将可执行文件标记为经验证与 Windows 数据执行保护功能兼容。Marks an executable as verified to be compatible with the Windows Data Execution Prevention feature.
/OPT/OPT 控制 LINK 优化。Controls LINK optimizations.
/ORDER/ORDER 按预先确定的顺序将 COMDAT 放置到映像中。Places COMDATs into the image in a predetermined order.
/OUT/OUT 指定输出文件名。Specifies the output file name.
/PDB/PDB 创建程序数据库 (PDB) 文件。Creates a program database (PDB) file.
/PDBALTPATH/PDBALTPATH 使用备用位置来保存 PDB 文件。Uses an alternate location to save a PDB file.
/PDBSTRIPPED/PDBSTRIPPED 创建没有私有符号的程序数据库 (PDB) 文件。Creates a program database (PDB) file that has no private symbols.
/PGD/PGD 为按配置文件优化指定 .pgd 文件。Specifies a .pgd file for profile-guided optimizations.
/POGOSAFEMODE/POGOSAFEMODE 已过时创建线程安全 PGO 检测生成。Obsolete Creates a thread-safe PGO instrumented build.
/PROFILE/PROFILE 生成一个可与“性能工具”探查器结合使用的输出文件。Produces an output file that can be used with the Performance Tools profiler.
/RELEASE/RELEASE 在 .exe 标头中设置校验和。Sets the Checksum in the .exe header.
/SAFESEH/SAFESEH 指定映像将包含安全异常处理程序表。Specifies that the image will contain a table of safe exception handlers.
/SECTION/SECTION 重写节的特性。Overrides the attributes of a section.
/ SOURCELINK/SOURCELINK 指定要添加到 PDB 的 SourceLink 文件。Specifies a SourceLink file to add to the PDB.
/STACK/STACK 设置堆栈的大小(以字节为单位)。Sets the size of the stack in bytes.
/STUB/STUB 将 MS-DOS 存根程序附加到 Win32 程序。Attaches an MS-DOS stub program to a Win32 program.
/SUBSYSTEM/SUBSYSTEM 通知操作系统如何运行 .exe 文件。Tells the operating system how to run the .exe file.
/SWAPRUN/SWAPRUN 通知操作系统在运行链接器输出之前将其复制到一个交换文件。Tells the operating system to copy the linker output to a swap file before it is run.
/TLBID/TLBID 指定链接器生成的类型库的资源 ID。Specifies the resource ID of the linker-generated type library.
/TLBOUT/TLBOUT 指定 .tlb 文件和其他 MIDL 输出文件的名称。Specifies the name of the .tlb file and other MIDL output files.
/TSAWARE/TSAWARE 创建专为在终端服务器下运行而设计的应用程序。Creates an application that is designed specifically to run under Terminal Server.
/USEPROFILE/USEPROFILE 使用按配置优化训练数据来创建优化的映像。Uses profile-guided optimization training data to create an optimized image.
/VERBOSE/VERBOSE 打印链接器进度消息。Prints linker progress messages.
/VERSION/VERSION 分配版本号。Assigns a version number.
/WHOLEARCHIVE/WHOLEARCHIVE 包含指定的静态库中的每个对象文件。Includes every object file from specified static libraries.
/WINMD/WINMD 允许生成 Windows 运行时元数据文件。Enables generation of a Windows Runtime Metadata file.
/WINMDFILE/WINMDFILE 指定由 /WINMD 链接器选项生成的 Windows 运行时元数据 (winmd) 输出文件的文件名。Specifies the file name for the Windows Runtime Metadata (winmd) output file that's generated by the /WINMD linker option.
/WINMDKEYFILE/WINMDKEYFILE 指定用来对 Windows 运行时元数据文件进行签名的密钥或密钥对。Specifies a key or key pair to sign a Windows Runtime Metadata file.
/WINMDKEYCONTAINER/WINMDKEYCONTAINER 指定用来对 Windows 元数据文件进行签名的密钥容器。Specifies a key container to sign a Windows Metadata file.
/WINMDDELAYSIGN/WINMDDELAYSIGN 通过将公钥放置在 winmd 文件中,对 Windows 运行时元数据 (winmd) 文件进行部分签名。Partially signs a Windows Runtime Metadata (.winmd) file by placing the public key in the winmd file.
/WX/WX 将链接器警告视为错误。Treats linker warnings as errors.

有关详细信息,请参阅 Compiler-Controlled LINK OptionsFor more information, see Compiler-Controlled LINK Options.

请参阅See Also

C/C++ 生成参考C/C++ Building Reference
设置链接器选项Setting Linker Options