最近在使用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 |
---|---|
等同于/Og /Os /Oy /Ob2 /Gs /GF /Gy,编译会进行代码最小优化 | |
等同于/Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy,编译器会进行代码最快优化.这是默认设置,也是release下采用的设置. | |
内联函数展开控制.0不执行内联展开,1只内联展开类内定义的内联函数,2内联展开所有的内联函数. | |
禁止优化可以方便代码调试, | |
包含子表达式优化,寄存器分配(常用变量和子表达式),循环优化. | |
使用内在函数可以减少函数调用的开销,通过编译器指令#pragma intrinsic来指定内在函数,内在函数列表在这里. | |
生成更小的代码. | |
生成更快的代码. | |
完全优化,生成更小更快的代码..等同/Ob /Og /Oi /Ot /Oy. | |
禁用调用堆栈./Oy- 开启调用堆栈方便调试. | |
根据处理器平台进行优化,可选{blend | ATOM | AMD64 | INTEL64}. |
Option | Purpose |
---|---|
指定使用的指令集,可选[IA32|SSE|SSE2|AVX]. | |
使用clr环境,具体可以参看clr选项. | |
指定如何处理异常. | |
指定浮点数行为. | |
对于wiindows可执行程序使用程序优化,声明为__declspec(thread)线程内的数据可以更快地访问,不要用于DLL程序. | |
调用约定. /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指令集及以上指令集的架构. | |
启用堆栈探针,结合/Gh指定探针钩子. | |
使用字符池,那么同一个字符串只会创建一份,使用时编译器会将多个变量指向同一地址. | |
探针钩子_penter,结合/Ge使用. | |
函数退出钩子_pexit. | |
使能全程序优化,通过/Gl-关闭全程序优化,只进行模块内优化. | |
使能最小构建.通过 .idb文件检测源码变化. | |
使能运行时类型信息 (RTTI),关闭时无法使用dynamic_cast和typeid,关闭后可以减少程序大小. | |
见/Gd部分. | |
检查缓冲区溢出. | |
设置栈探针触发前函数可以使用多少内存.默认为4kb | |
对线程内数据支持fiber safety,禁用/Og对这种数据类型的优化. | |
见/Gd部分. | |
使能全局数据优化,将全局数据放在COMDAT段. | |
使能异常处理(假定extern c函数从不抛出异常),已经废弃,使用/Gh替代. | |
允许编译器组织个体函数. | |
使能运行时错误检测.已废弃. | |
见Gd部分. | |
强制将寄存器参数传入栈中,是的release下也能进行调试. (only for x64 native and cross compile). | |
使得创建的映像文件支持hot patching,利用hot patching可以hack函数行为. | |
为超越函数(对数函数,反三角函数,指数函数等)生成内联代码. | |
根据ASCII C标准,浮点转整形是会忽略小数部分的(x86 only),通过/QIfist可以关闭这个特性,根据intel处理器参考文档,其提供四种 舍入方式1)取最近的整数,类似[x].2)舍入正无穷.3)舍入负无穷.4)舍入到0.默认的舍入模式为1),可以通过运行时函数 _control87, _controlfp, _control87_2来修改舍入方式. | |
当选项/fp:except打开的时候,编译器会在每个try块内的语句附近插入一条fwait指令,这样遇到异常时,编译器可以确定是出现在哪行.开启这个选项则会关闭编译器的这个特性. | |
开启循环并行计算特性,利用多核并行的优势,能显著提高执行速度.#pragma loop()告诉编译器可以惊醒并行优化. | |
设置循环并行计算报告等级,结合/Qpar选项使用. | |
禁用浮点数加载优化,使用整数加载指令.(x86 only)防止加载异常情况发生,比如NAN. | |
Enables reporting levels for automatic vectorization. | |
使能运行时错误检测. | |
设置关键字volatile解释方式. |
Option | Purpose |
---|---|
为源码生成.xdc格式的文档,xdc格式可以通过xdcmake.exe工具输出xml.微软推荐的文档标签. | |
/FA输出汇编代码.asm. /FAs输出机器码和汇编码.cond. /FAs输出源码和汇编码.asm. /FAu使用UTF8编码输出. | |
/FA可加参数的版本. | |
指定调试文件pdb的名称. | |
指定输出文件exe或者DLL的名称. | |
指定预处理输出文件名称. | |
指定输出的段档案名称. | |
指定编译文件.obj的名称. | |
指定要使用的预处理头文件.pch. | |
指定创建的.sbr文件名称,BSCMAKE工具使用此文件来创建浏览信息. |
Option | Purpose |
---|---|
指定#using指令搜索目录. | |
预处理时保留注释. | |
定义常量和宏. | |
将预处理器输出复制到标准输出.使用#line指令对预处理过的文件行进行重排,是的错误指向的函数为源文件的真实行数. | |
同上,但是不加#line指令,错误行数指向预处理过后的行数,而不是源文件行数. | |
强制为源文件添加头文件. | |
强制为源文件添加#using文件. | |
合并注入代码,通过穿件.mgr文件进行代码注入,注意.mgr文件内不支持宏展开, | |
指定头文件包含搜索目录. | |
将预处理输出到指定文件. | |
#undef预定义符号. | |
#undef微软预定义符号. | |
禁用从 PATH和INCLUDE变量定义的路径搜索包含头文件. |
Option | Purpose |
---|---|
使能 #pragma omp指令,支持opemMP 2.0标准,高效多处理器操作接口(待学习). | |
vtordisp(virtual construction/destruction displacement)待学习. | |
必须先定义类,才能定义指向类成员的指针. | |
可以在类定义之前定义类成员指针,可以解决类成员交叉引用的问题. | |
编译器表示类成员变量指针的方式为多继承. | |
编译器表示类成员变量指针的方式为单继承. | |
编译器表示类成员变量指针的方式为虚继承. | |
调试信息配置.所有调试信息输出到.obj,不产生.pdb文件. | |
禁用ANSI C和 ANSI C++标准以外的语言扩展.利用此选项来编写多平台代码. | |
指定在语言扩展下的语言行为. | |
和/Za相反,启用微软的语言扩展. | |
生成函数原型. | |
调试信息配置.和/Zi一样,但是会禁用#pragma optimize指令,支持编辑并继续. | |
控制调试信息配置.输出类型了符号调试信息到.pdb文件,此选项不影响优化. | |
忽略运行时函数库.C Runtime Library的特性不再使用. | |
/Zp n | 指定结构体成员的对齐大小. |
编译器只进行语法检测. | |
进行windows运行时编译,用于生成支持微软应用商店的应用. |
Option | Purpose |
---|---|
设置栈大小(字节). | |
创建动态连接库,如果没有制定导出文件.exp,则会创建导入库.lib.默认使用多线程C运行库. | |
创建可调试的动态链接库. | |
传入链接器参数. | |
创建微软中间件模块. | |
编译使用多线程库的Dll,MSVCRT.lib. | |
编译使用调试版多线程库, MSVCRTD.lib. | |
编译使用多线程库的可执行文件,LIBCMT.lib. | |
编译使用可调式多线程库的可执行文件 LIBCMTD.lib. |
预编译头文件:
Option | Purpose |
---|---|
I忽略所有的预编译头文件选项. | |
创建预编译头文件 | |
将预编译头文件中的所有调试信息输出到.obj文件中. | |
使用预编译头文件. |
Option | Purpose |
---|---|
编译器帮助. | |
指定编译器响应文件,文件内所有的命令都会作用到命令行,尤其适合命令长度大于127个字符的情况. | |
使能代码分析. | |
可寻址段从65,536 (2^16)个增加到 4,294,967,296 (2^32)个. | |
只编译,不链接. | |
开启错误报告. | |
输出诊断信息时打印源文件的绝对路径. | |
强制同步写pdb文件. | |
限制外部名字长度,默认为2047,/H选项只能指定比2047小的长度.. | |
帮助. | |
使默认char的为unsigned char,并且转换为整形时为零扩展. | |
创建内核模式二进制文件. | |
并行构建. | |
禁用l编译器信息显示. | |
开启安全开发周期检测,产生更多的编译警告. | |
在编译期输出所有包含的头文件. | |
/Tc指定源文件为C源文件,即使后缀不对./TC对待的所有源文件都是C源文件. | |
/Tp指定源文件为C++源文件,即使后缀不对./TP吧所有源文件当C++源文件对待. | |
指定版本或者版权信息,将会输出到.obj. | |
输出所有警告. | |
设置警告等级. | |
关闭警告. | |
输出更多的诊断信息. | |
检测64位系统上可能存在的类型问题,典型的有int, long, pointer. | |
Places complete debugging information in all object files. | |
为调试库注入pch引用,在创建使用预编译头文件的调试库出错时可能需要设置这个选项. | |
指定构建预编译头文件能使用的最大内存. |
LINK.EXE
Option | Purpose |
---|---|
Specifies a response file. | |
Specifies the alignment of each section. | |
Specifies that a DLL cannot be bound. | |
Specifies behavior for manifest lookup. | |
Specifies whether the app must run within an appcontainer process environment. | |
Adds the DebuggableAttribute to a managed image. | |
Creates a link to a managed resource. | |
Specifies that a Microsoft intermediate language (MSIL) module should be imported into the assembly. | |
Embeds a managed resource file in an assembly. | |
Sets a base address for the program. | |
Sets the type (IJW, pure, or safe) of a CLR image. | |
Preserves the last error code of functions that are called through the P/Invoke mechanism. | |
Specifies the threading attribute to apply to the entry point of your CLR program. | |
Specifies whether the linker will apply the SuppressUnmanagedCodeSecurity attribute to linker-generated PInvoke stubs that call from managed code into native DLLs. | |
Creates debugging information. | |
Passes a module-definition (.def) file to the linker. | |
Searches the specified library when external references are resolved. | |
Controls the delayed loading of DLLs. | |
Causes the delayed loading of the specified DLL. | |
Partially signs an assembly. | |
Builds a DLL. | |
Creates a kernel mode driver. | |
Specifies whether to generate an executable image that can be randomly rebased at load time by using the address space layout randomization (ASLR) feature. | |
Sets the starting address. | |
Reports internal linker errors to Microsoft. | |
Exports a function. | |
Creates a program that can be loaded only at its preferred base address. | |
Forces a link to complete even with unresolved symbols or symbols defined more than once. | |
Creates an image that can be hot patched. | |
Sets the size of the heap, in bytes. | |
Specifies support for high-entropy 64-bit address space layout randomization (ASLR). | |
Specifies the name of the .idl file and other MIDL output files. | |
Prevents the processing of attribute information into an .idl file. | |
Overrides the default import library name. | |
Forces symbol references. | |
Controls incremental linking. | |
Specifies that the module requires a signature check at load time. | |
Specifies a key container to sign an assembly. | |
Specifies a key or key pair to sign an assembly. | |
Tells the compiler that the application supports addresses larger than two gigabytes | |
Enables user override of the environmental library path. | |
Specifies link-time code generation. | |
Specifies the target platform. | |
Creates a side-by-side manifest file and optionally embeds it in the binary. | |
Specifies a <dependentAssembly> section in the manifest file. | |
Changes the default name of the manifest file. | |
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. | |
Specifies whether User Account Control (UAC) information is embedded in the program manifest. | |
Creates a mapfile. | |
Includes the specified information in the mapfile. | |
Combines sections. | |
Specifies MIDL command-line options. | |
Suppresses the creation of a .NET Framework assembly. | |
Ignores all (or the specified) default libraries when external references are resolved. | |
Creates a resource-only DLL. | |
Suppresses the startup banner. | |
Marks an executable as verified to be compatible with the Windows Data Execution Prevention feature. | |
Controls LINK optimizations. | |
Places COMDATs into the image in a predetermined order. | |
Specifies the output file name. | |
Creates a program database (PDB) file. | |
Uses an alternate location to save a PDB file. | |
Creates a program database (PDB) file that has no private symbols. | |
Specifies a .pgd file for profile-guided optimizations. | |
Produces an output file that can be used with the Performance Tools profiler. | |
Sets the Checksum in the .exe header. | |
Specifies that the image will contain a table of safe exception handlers. | |
Overrides the attributes of a section. | |
Sets the size of the stack in bytes. | |
Attaches an MS-DOS stub program to a Win32 program. | |
Tells the operating system how to run the .exe file. | |
Tells the operating system to copy the linker output to a swap file before it is run. | |
Specifies the resource ID of the linker-generated type library. | |
Specifies the name of the .tlb file and other MIDL output files. | |
Creates an application that is designed specifically to run under Terminal Server. | |
Prints linker progress messages. | |
Assigns a version number. | |
Enables generation of a Windows Runtime Metadata file. | |
Specifies the file name for the Windows Runtime Metadata (winmd) output file that's generated by the /WINMD linker option. | |
Specifies a key or key pair to sign a Windows Runtime Metadata file. | |
Specifies a key container to sign a Windows Metadata file. | |
Partially signs a Windows Runtime Metadata (.winmd) file by placing the public key in the winmd file. | |
Treats linker warnings as errors. |