简体   繁体   English

如何设置发布/调试模式以使用 Microsoft C++ 工具集在命令提示符下编译 cpp 文件

[英]How to set release/debug mode to compile a cpp file at a command prompt using Microsoft C++ toolset

I have a code that works fine in VS2019 release x86 mode but not in debug mode.的代码在 VS2019 版本 x86 模式下运行良好,但在调试模式下运行良好。 Is there any way to use the release mode feature in the command line?有没有办法在命令行中使用发布模式功能? For example an option for CL or link.exe.例如 CL 或 link.exe 的选项。 The CL command line syntax is CL 命令行语法是

CL [option...] file... [option | CL [选项...] 文件... [选项 | file]... [lib...] [@command-file] [/link link-opt...]文件]... [lib...] [@command-file] [/link link-opt...]

Here is the list of MSVC compiler options: MSVC Compiler Options There are some optimization options such as /O1 /O2 but they don't produce the same results as the VS release build.下面是 MSVC 编译器选项的列表: MSVC 编译器选项有一些优化选项,例如/O1 /O2 ,但它们不会产生与 VS 版本构建相同的结果。 Am I searching for the wrong thing?我在寻找错误的东西吗? Thank you in advance for your help.预先感谢您的帮助。

Update更新

I found out the correct option for my code is /MD for Runtime Library setting.我发现我的代码的正确选项是/MD用于运行时库设置。 So using the following line in command prompt, the release-mode results are reproduced:因此,在命令提示符下使用以下行,复制了发布模式的结果:

>cl /MD app.cpp

Visual Studio's configuration properties for your project will tell you exactly what compiler and linker options are being used in each build configuration. Visual Studio 的项目配置属性将准确告诉您每个构建配置中使用的编译器和 linker 选项。 See: https://docs.microsoft.com/en-us/cpp/build/working-with-project-properties?view=vs-2019请参阅: https://docs.microsoft.com/en-us/cpp/build/working-with-project-properties?view=vs-2019

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C++ 调试宏在发布模式下编译失败 - C++ Debug macro failing compile in release mode 如何使用 vscode 在发布模式下编译 c++ - how to compile c++ in release mode with vscode 如何使用命令提示符、记事本和 MinGW 编译带有主 header 和实现文件的 C++ 程序? - How to compile C++ program with a main, header and implementation file using command prompt, notepad and MinGW? 如何在Windows命令提示符下使用Dev C ++编译器编译c ++程序? - How to compile a c++ program using Dev C++ compiler in windows command prompt? 如何使用命令行在C ++中编译和链接分隔的.h和.cpp文件? - How to compile and link separated .h and .cpp files in C++ using the command line? 如何检查可执行文件或 DLL 是在发布还是调试模式下构建的 (C++) - How to check if an executable or DLL is build in Release or Debug mode (C++) 运行时如何在 Visual Studio C++ 中确定调试或发布模式 - Runtime how to determine Debug or release mode in visual studio c++ c++ 在调试中编译错误但在发布中没有 - c++ compile error in debug but not in release 试图编译一个 cpp 文件,但命令提示符说找不到文件 - Trying to compile a cpp file but command prompt saying file not found 无法编译C ++ file.cpp。 C ++ 98模式 - Can't compile C++ file.cpp. C++98 mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM