cl.exe 和 ml.exe 的问题

2021-12-31 00:00:00 visual-studio compiler-errors c++ cl.exe

我使用 cl 命令编译了一个 cpp 文件:

I used cl command to compile a cpp file:

cl test.cpp  //the generated  test.exe can work well

然后我用了另一种方式:

then I used another way:

cl /Fa /c test.cpp   //generate a test.asm assembly file
ml test.asm   // there failed!!!

为什么?如何解决?

源代码:

//:test.cpp 

 #include<iostream>
 using namespace std;
 int main()
  {
    cout<<"hello
";
  }

错误信息:

组装:test.asmtest.asm(1669):致命错误 A1010:不匹配的块嵌套

Assembling: test.asm test.asm(1669) : fatal error A1010: unmatched block nesting

: ??$?6U?$char_traits@D@std@@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z

: ??$?6U?$char_trait s@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z

<小时>

今天我用c写了另一个代码


today I write another code in c

//test.cpp
#include<stdio.h>
void main()
{
  printf("hello");
}

然后我编译代码

cl /Fa /c test.cpp
ml test.asm //ok!

可能是C和C++的区别.这让我困惑了几天.:(

It may be the difference in C and C++. This confuses me a few days. :(

怎么解决?请帮帮我.

推荐答案

生成异常处理代码时,编译器生成无效的程序集列表.Microsoft Connect 上存在一个错误:http://connect.microsoft.com/VisualStudio/feedback/details/556051/cl-facs-generates-bad-masm-for-c-exception-handlers

The compiler produces an invalid assembly listing when exception handling code is produced. There's a bug open on Microsoft Connect: http://connect.microsoft.com/VisualStudio/feedback/details/556051/cl-facs-generates-bad-masm-for-c-exception-handlers

在对错误的回应中,有一个半心半意的我们将考虑修复此问题"以及列出由 C/C++ 编译器生成的文件仅供参考"的免责声明.

In a response to the bug, there's a half-hearted "we will consider fixing this" along with a disclaimer that "listing files generated by the C/C++ compiler are for informational purposes".

您似乎可以针对此特定问题进行脚本化"修复:

It looks like you might be able to have a "scriptable" fix for this particular problem:

  • 剪切text$x ENDS 语句之后的ENDP 语句,
  • 将其粘贴在之前的 _TEXT ENDS 语句之前
  • cut the ENDP statement that follows a text$x ENDS statement,
  • paste it just before the previous _TEXT ENDS statement

至少这看起来是由您的简单程序生成的 asm 文件中的模式 - 我不知道该模式是否普遍适用.

At least that looks to be the pattern in the asm file generated by your simple program - I don't know if that pattern would hold generally.

不幸的是,在应用此修复程序后,使用 fs 覆盖和几个未定义符号的指令出现了几个新问题.谁知道当你用一个更复杂的程序尝试这个时,你还会遇到什么?

Unfortunately, after applying this fix, several new problems crop up with instructions using fs overrides and a couple undefined symbols. Who knows what else you'd run into once you tried this with a more complex program?

相关文章