Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

c++ - a problem with cl.exe and ml.exe

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...