MSVC编译器cl参数总结

/c (Compile Without Linking)

只编译不链接。
Compile or assemble the source files, but do not link.
Compiling with /c creates .obj files only. You must call LINK explicitly with the proper files and options to perform the linking phase of the build.

/EH (Exception handling model) 异常捕获

error handling
/EHa /EHs /EHc /EHr /EHsc

参数 全称含义 作用说明
/EHs 同步异常 启用标准 C++ 栈展开,catch(...) 仅捕获 C++ 同步异常,不捕获结构化异常
/EHa 异步+同步异常 启用标准 C++ 栈展开,catch(...) 同时捕获 C++ 同步异常和结构化异步异常(SEH)。会覆盖 /EHs 和 /EHc
/EHc extern "C" 假设 与 /EHs 搭配使用时,编译器假设 extern "C" 函数不会抛出 C++ 异常。可优化代码,但若违反假设会导致未定义行为
/EHr noexcept 运行时检查 强制为所有 noexcept 函数生成运行时终止检查(默认可能优化掉)。有助于发现从 noexcept 函数逃逸的异常
/EH 参数后加 - 清除选项 例如 /EHc- 表示关闭之前指定的 /EHc 效果

https://www.geeksforgeeks.org/cpp/exception-handling-c/

/Fo (Object File Name) 设置obj文件名或输出目录

#语法1 没有空格
/Fo"pathname" 
#语法2 有空格
/Fo:[ ]"pathname" 

A directory is indicated by a trailing slash or backslash in the pathname argument. Use an escaped backslash (a double backslash), if you're using a quoted path.

pathname变量 末尾有斜杠/或者反斜杠\,则表示目录。 如果是引号内,则需要转义。

CL /Fo: "test" /EHsc /c sample1.cpp
CL /Fo"D:\\intermediate\\" /EHsc /c sample1.cpp sample2.cpp

/I (Additional include directories) 额外的include目录

将 目录 添加到 include 文件搜索目录中。要想添加多个目录,需要多次调用。 目录搜索 只有 找到目标include文件后 才结束.
To add more than one directory, use this option more than once. Directories are searched only until the specified include file is found.

/I directory
posted @ 2026-03-26 21:20  dewxin  阅读(2)  评论(0)    收藏  举报