cl.exe 和 ml.exe 的问题

发布于 2024-12-05 16:40:07 字数 881 浏览 0 评论 0原文

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

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

然后我使用另一种方式:

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\n";
  }

错误信息:

汇编:test.asm test.asm(1669) : 致命错误 A1010: 不匹配的块嵌套

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


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

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

,然后编译了代码

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

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

怎么解决?请帮帮我。

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!!!

why? How to solve it?

source code:

//:test.cpp 

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

wrong information:

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

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


today I write another code in c

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

then I compile the code

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

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

how to solve it? please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野心澎湃 2024-12-12 16:40:07

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

bug,有一个半心半意的“我们将考虑修复这个问题”以及一个免责声明,“列出由 C/C++ 编译器生成的文件仅供参考”。

看来您可以针对此特定问题进行“可编写脚本”修复:

  • 剪切 text$x ENDS 语句后面的 ENDP 语句,
  • 将其粘贴到之前前面的 _TEXT ENDS 语句

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

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

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

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:

  • cut the ENDP statement that follows a text$x ENDS statement,
  • paste it just before the previous _TEXT ENDS statement

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.

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文