cl.exe 和 ml.exe 的问题
我使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当生成异常处理代码时,编译器会生成无效的程序集列表。 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:
ENDP
statement that follows atext$x ENDS
statement,_TEXT ENDS
statementAt 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?