cl.exe,link.exe编译选项以及在windows下编译lua 5.2.2

来源:互联网 发布:数据管理制度 编辑:程序博客网 时间:2024/04/29 16:18

最近在使用lua,环境是windows.lua源码只提供了Makefile配置,之前多用CMake编译开源项目,看到lua编译文档中也有提供CMakeLists配置文件,因为没有在windows下单独使用cl和link的经验,所以准备先学习一下编译器和链接器选项.


CL.EXE

在MSDN的Compiler Options文档可以学习到cl的完整编译选项.这里(Compiler Options Listed by Category)提供完整的选项分类(/option和-option是一样的).

编译优化:

Option

Purpose

/O1

等同于/Og /Os /Oy /Ob2 /Gs /GF /Gy,编译会进行代码最小优化

/O2

等同于/Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy,编译器会进行代码最快优化.这是默认设置,也是release下采用的设置.

/Ob

内联函数展开控制.0不执行内联展开,1只内联展开类内定义的内联函数,2内联展开所有的内联函数.

/Od

禁止优化可以方便代码调试,

/Og

包含子表达式优化,寄存器分配(常用变量和子表达式),循环优化.

/Oi

使用内在函数可以减少函数调用的开销,通过编译器指令#pragma intrinsic来指定内在函数,内在函数列表在这里.

/Os

生成更小的代码.

/Ot

生成更快的代码.

/Ox

完全优化,生成更小更快的代码..等同/Ob /Og /Oi /Ot /Oy.

/Oy

禁用调用堆栈./Oy- 开启调用堆栈方便调试.

/favor

根据处理器平台进行优化,可选{blend | ATOM | AMD64 | INTEL64}.

代码生成:

Option

Purpose

/arch

指定使用的指令集,可选[IA32|SSE|SSE2|AVX].

/clr

使用clr环境,具体可以参看clr选项.

/EH

指定如何处理异常.

/fp

指定浮点数行为.

/GA

对于wiindows可执行程序使用程序优化,声明为__declspec(thread)线程内的数据可以更快地访问,不要用于DLL程序.

/Gd

调用约定.

/Gd:将除成员函数以外的函数都指定为_cdecl(参数传入从右到左,函数调用从栈内pop,下划线修饰函数,没有大小写转换),程式内

制定的 __stdcall__fastcall, or__vectorcall都会被覆盖.

/Gz:指定调用约定为_stdcall(对成员函数,main函数,和指定了调用约定的函数无效)._stdcall(参数右到左传入,除了指针和

引用以外都按值传入对于类会调用复制构造函数,函数以下划线_作为前缀,参数用@连接,无大小写转换)只对x86有效.

/Gr:指定_fastcall(头两个DWORD的参数从左到又传入ECX和EDX寄存器,剩下的从右到左传入,以@parameter-size<十进制>

作为函数名前缀,无大小写转换)调用约定,指定规则和适用平台和_stdcall一样.

/Gv指定_vectorcall(尽可能使用寄存器传入参数,@@parameter-size<十进制>作为函数名前缀,无大小写转换)调用约定,对

含有可变参数的函数无效,支持x86和x64支持SSE2指令集及以上指令集的架构.

/Ge

启用堆栈探针,结合/Gh指定探针钩子.

/GF

使用字符池,那么同一个字符串只会创建一份,使用时编译器会将多个变量指向同一地址.

/Gh

探针钩子_penter,结合/Ge使用.

/GH

函数退出钩子_pexit.

/GL

使能全程序优化,通过/Gl-关闭全程序优化,只进行模块内优化.

/Gm

使能最小构建.通过 .idb文件检测源码变化.

/GR

使能运行时类型信息 (RTTI),关闭时无法使用dynamic_cast和typeid,关闭后可以减少程序大小.

/Gr

见/Gd部分.

/GS

检查缓冲区溢出.

/Gs

设置栈探针触发前函数可以使用多少内存.默认为4kb

/GT

对线程内数据支持fiber safety,禁用/Og对这种数据类型的优化.

/Gv

见/Gd部分.

/Gw

使能全局数据优化,将全局数据放在COMDAT段.

/GX

使能异常处理(假定extern c函数从不抛出异常),已经废弃,使用/Gh替代.

/Gy

允许编译器组织个体函数.

/GZ

使能运行时错误检测.已废弃.

/Gz

见Gd部分.

/homeparams

强制将寄存器参数传入栈中,是的release下也能进行调试. (only for x64 native and cross compile).

/hotpatch

使得创建的映像文件支持hot patching,利用hot patching可以hack函数行为.

/Qfast_transcendentals

超越函数(对数函数反三角函数指数函数等)生成内联代码.

/QIfist

根据ASCII C标准,浮点转整形是会忽略小数部分的(x86 only),通过/QIfist可以关闭这个特性,根据intel处理器参考文档,其提供四种

舍入方式1)取最近的整数,类似[x].2)舍入正无穷.3)舍入负无穷.4)舍入到0.默认的舍入模式为1),可以通过运行时函数 _control87,

 _controlfp, _control87_2来修改舍入方式.

/Qimprecise_fwaits

当选项/fp:except打开的时候,编译器会在每个try块内的语句附近插入一条fwait指令,这样遇到异常时,编译器可以确定是出现在哪行.开启这个选项则会关闭编译器的这个特性.

/Qpar

开启循环并行计算特性,利用多核并行的优势,能显著提高执行速度.#pragma loop()告诉编译器可以惊醒并行优化.

/Qpar-report

设置循环并行计算报告等级,结合/Qpar选项使用.

/Qsafe_fp_loads

禁用浮点数加载优化,使用整数加载指令.(x86 only)防止加载异常情况发生,比如NAN.

/Qvec-report (Auto-Vectorizer Reporting Level)

Enables reporting levels for automatic vectorization.

/RTC

使能运行时错误检测.

/volatile

设置关键字volatile解释方式.

输出设置:

Option

Purpose

/doc

为源码生成.xdc格式的文档,xdc格式可以通过xdcmake.exe工具输出xml.微软推荐的文档标签.

/FA

/FA输出汇编代码.asm. /FAs输出机器码和汇编码.cond. /FAs输出源码和汇编码.asm. /FAu使用UTF8编码输出.

/Fa

/FA可加参数的版本.

/Fd

指定调试文件pdb的名称.

/Fe

指定输出文件exe或者DLL的名称.

/Fi

指定预处理输出文件名称.

/Fm

指定输出的段档案名称.

/Fo

指定编译文件.obj的名称.

/Fp

指定要使用的预处理头文件.pch.

/FR /Fr

指定创建的.sbr文件名称,BSCMAKE工具使用此文件来创建浏览信息.

预处理器:

Option

Purpose

/AI

指定#using指令搜索目录.

/C

预处理时保留注释.

/D

定义常量和宏.

/E

将预处理器输出复制到标准输出.使用#line指令对预处理过的文件行进行重排,是的错误指向的函数为源文件的真实行数.

/EP

同上,但是不加#line指令,错误行数指向预处理过后的行数,而不是源文件行数.

/FI

强制为源文件添加头文件.

/FU

强制为源文件添加#using文件.

/Fx

合并注入代码,通过穿件.mgr文件进行代码注入,注意.mgr文件内不支持宏展开,

/I

指定头文件包含搜索目录.

/P

将预处理输出到指定文件.

/U

#undef预定义符号.

/u

#undef微软预定义符号.

/X

禁用从 PATH和INCLUDE变量定义的路径搜索包含头文件.

语言:

Option

Purpose

/openmp

使能 #pragma omp指令,支持opemMP 2.0标准,高效多处理器操作接口(待学习).

/vd

vtordisp(virtual construction/destruction displacement)待学习.

/vmb

必须先定义类,才能定义指向类成员的指针.

/vmg

可以在类定义之前定义类成员指针,可以解决类成员交叉引用的问题.

/vmm

编译器表示类成员变量指针的方式为多继承.

/vms

编译器表示类成员变量指针的方式为单继承.

/vmv

编译器表示类成员变量指针的方式为虚继承.

/Z7

调试信息配置.所有调试信息输出到.obj,不产生.pdb文件.

/Za

禁用ANSI C和 ANSI C++标准以外的语言扩展.利用此选项来编写多平台代码.

/Zc

指定在语言扩展下的语言行为.

/Ze

和/Za相反,启用微软的语言扩展.

/Zg

生成函数原型.

/ZI

调试信息配置.和/Zi一样,但是会禁用#pragma optimize指令,支持编辑并继续.

/Zi

控制调试信息配置.输出类型了符号调试信息到.pdb文件,此选项不影响优化.

/Zl

忽略运行时函数库.C Runtime Library的特性不再使用.

/Zp n

指定结构体成员的对齐大小.

/Zs

编译器只进行语法检测.

/ZW

进行windows运行时编译,用于生成支持微软应用商店的应用.

链接:

Option

Purpose

/F

设置栈大小(字节).

/LD

创建动态连接库,如果没有制定导出文件.exp,则会创建导入库.lib.默认使用多线程C运行库.

/LDd

创建可调试的动态链接库.

/link

传入链接器参数.

/LN

创建微软中间件模块.

/MD

编译使用多线程库的Dll,MSVCRT.lib.

/MDd

编译使用调试版多线程库, MSVCRTD.lib.

/MT

编译使用多线程库的可执行文件,LIBCMT.lib.

/MTd

编译使用可调式多线程库的可执行文件 LIBCMTD.lib.


预编译头文件:

Option

Purpose

/Y-

I忽略所有的预编译头文件选项.

/Yc

创建预编译头文件

/Yd

将预编译头文件中的所有调试信息输出到.obj文件中.

/Yu

使用预编译头文件.

杂项:

Option

Purpose

/?

编译器帮助.

@

指定编译器响应文件,文件内所有的命令都会作用到命令行,尤其适合命令长度大于127个字符的情况.

/analyze

使能代码分析.

/bigobj

可寻址段从65,536 (2^16)个增加到 4,294,967,296 (2^32)个.

/c

只编译,不链接.

/errorReport

开启错误报告.

/FC

输出诊断信息时打印源文件的绝对路径.

/FS

强制同步写pdb文件.

/H

限制外部名字长度,默认为2047,/H选项只能指定比2047小的长度..

/HELP

帮助.

/J

使默认char的为unsigned char,并且转换为整形时为零扩展.

/kernel

创建内核模式二进制文件.

/MP

并行构建.

/nologo

禁用l编译器信息显示.

/sdl

开启安全开发周期检测,产生更多的编译警告.

/showIncludes

在编译期输出所有包含的头文件.

/Tc /TC

/Tc指定源文件为C源文件,即使后缀不对./TC对待的所有源文件都是C源文件.

/Tp /TP

/Tp指定源文件为C++源文件,即使后缀不对./TP吧所有源文件当C++源文件对待.

/V

指定版本或者版权信息,将会输出到.obj.

/Wall

输出所有警告.

/W

设置警告等级.

/w

关闭警告.

/WL

输出更多的诊断信息.

/Wp64

检测64位系统上可能存在的类型问题,典型的有int, long, pointer.

/Yd

Places complete debugging information in all object files.

/Yl

为调试库注入pch引用,在创建使用预编译头文件的调试库出错时可能需要设置这个选项.

/Zm

指定构建预编译头文件能使用的最大内存.


LINK.EXE

Option

Purpose

@

Specifies a response file.

/ALIGN

Specifies the alignment of each section.

/ALLOWBIND

Specifies that a DLL cannot be bound.

/ALLOWISOLATION

Specifies behavior for manifest lookup.

/APPCONTAINER

Specifies whether the app must run within an appcontainer process environment.

/ASSEMBLYDEBUG

Adds the DebuggableAttribute to a managed image.

/ASSEMBLYLINKRESOURCE

Creates a link to a managed resource.

/ASSEMBLYMODULE

Specifies that a Microsoft intermediate language (MSIL) module should be imported into the assembly.

/ASSEMBLYRESOURCE

Embeds a managed resource file in an assembly.

/BASE

Sets a base address for the program.

/CLRIMAGETYPE

Sets the type (IJW, pure, or safe) of a CLR image.

/CLRSUPPORTLASTERROR

Preserves the last error code of functions that are called through the P/Invoke mechanism.

/CLRTHREADATTRIBUTE

Specifies the threading attribute to apply to the entry point of your CLR program.

/CLRUNMANAGEDCODECHECK

Specifies whether the linker will apply the SuppressUnmanagedCodeSecurity attribute to linker-generated PInvoke stubs that call from managed code into native DLLs.

/DEBUG

Creates debugging information.

/DEF

Passes a module-definition (.def) file to the linker.

/DEFAULTLIB

Searches the specified library when external references are resolved.

/DELAY

Controls the delayed loading of DLLs.

/DELAYLOAD

Causes the delayed loading of the specified DLL.

/DELAYSIGN

Partially signs an assembly.

/DLL

Builds a DLL.

/DRIVER

Creates a kernel mode driver.

/DYNAMICBASE

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

Sets the starting address.

/errorReport

Reports internal linker errors to Microsoft.

/EXPORT

Exports a function.

/FIXED

Creates a program that can be loaded only at its preferred base address.

/FORCE

Forces a link to complete even with unresolved symbols or symbols defined more than once.

/FUNCTIONPADMIN

Creates an image that can be hot patched.

/HEAP

Sets the size of the heap, in bytes.

/HIGHENTROPYVA

Specifies support for high-entropy 64-bit address space layout randomization (ASLR).

/IDLOUT

Specifies the name of the .idl file and other MIDL output files.

/IGNOREIDL

Prevents the processing of attribute information into an .idl file.

/IMPLIB

Overrides the default import library name.

/INCLUDE

Forces symbol references.

/INCREMENTAL

Controls incremental linking.

/INTEGRITYCHECK

Specifies that the module requires a signature check at load time.

/KEYCONTAINER

Specifies a key container to sign an assembly.

/KEYFILE

Specifies a key or key pair to sign an assembly.

/LARGEADDRESSAWARE

Tells the compiler that the application supports addresses larger than two gigabytes

/LIBPATH

Enables user override of the environmental library path.

/LTCG

Specifies link-time code generation.

/MACHINE

Specifies the target platform.

/MANIFEST

Creates a side-by-side manifest file and optionally embeds it in the binary.

/MANIFESTDEPENDENCY

Specifies a <dependentAssembly> section in the manifest file.

/MANIFESTFILE

Changes the default name of the manifest file.

/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

Specifies whether User Account Control (UAC) information is embedded in the program manifest.

/MAP

Creates a mapfile.

/MAPINFO

Includes the specified information in the mapfile.

/MERGE

Combines sections.

/MIDL

Specifies MIDL command-line options.

/NOASSEMBLY

Suppresses the creation of a .NET Framework assembly.

/NODEFAULTLIB

Ignores all (or the specified) default libraries when external references are resolved.

/NOENTRY

Creates a resource-only DLL.

/NOLOGO

Suppresses the startup banner.

/NXCOMPAT

Marks an executable as verified to be compatible with the Windows Data Execution Prevention feature.

/OPT

Controls LINK optimizations.

/ORDER

Places COMDATs into the image in a predetermined order.

/OUT

Specifies the output file name.

/PDB

Creates a program database (PDB) file.

/PDBALTPATH

Uses an alternate location to save a PDB file.

/PDBSTRIPPED

Creates a program database (PDB) file that has no private symbols.

/PGD

Specifies a .pgd file for profile-guided optimizations.

/PROFILE

Produces an output file that can be used with the Performance Tools profiler.

/RELEASE

Sets the Checksum in the .exe header.

/SAFESEH

Specifies that the image will contain a table of safe exception handlers.

/SECTION

Overrides the attributes of a section.

/STACK

Sets the size of the stack in bytes.

/STUB

Attaches an MS-DOS stub program to a Win32 program.

/SUBSYSTEM

Tells the operating system how to run the .exe file.

/SWAPRUN

Tells the operating system to copy the linker output to a swap file before it is run.

/TLBID

Specifies the resource ID of the linker-generated type library.

/TLBOUT

Specifies the name of the .tlb file and other MIDL output files.

/TSAWARE

Creates an application that is designed specifically to run under Terminal Server.

/VERBOSE

Prints linker progress messages.

/VERSION

Assigns a version number.

/WINMD

Enables generation of a Windows Runtime Metadata file.

/WINMDFILE

Specifies the file name for the Windows Runtime Metadata (winmd) output file that's generated by the /WINMD linker option.

/WINMDKEYFILE

Specifies a key or key pair to sign a Windows Runtime Metadata file.

/WINMDKEYCONTAINER

Specifies a key container to sign a Windows Metadata file.

/WINMDDELAYSIGN

Partially signs a Windows Runtime Metadata (.winmd) file by placing the public key in the winmd file.

/WX

Treats linker warnings as errors.


0 0
原创粉丝点击