2011-09-16 48 views
5
#include<iostream> 
#include<cstdlib> 
#include<cstring> 
#include<cstdio> 
using namespace std; 

class Book{ 
    public: 
     int a; 
     int b; 
}; 

int main() 
{ 
    Book b1; 
    b1.a = 10; 
    b1.b = 20; 
    cout<< b1.a << " " <<b1.b; 
} 

当我们使用使用clang ++生成的可执行文件变得疯狂

clang++ test.cc -o a.exe 

编译上面的代码并运行a.exe时效果很好。但是当我们使用

clang++ test.cc -emit-llvm -S -o a.exe 

编译相同的程序时,现在当我们运行它时,程序会因启动ntvdm.exe而疯狂(可以在进程资源管理器中看到)并且命令提示符开始表现得很奇怪。

软件堆栈:

clang version 2.9 (tags/RELEASE_29/final) 
Target: i386-pc-mingw32 
Thread model: posix 
+0

看起来非常好。 –

+0

你忘了将'-Wall'传递给'clang ++' –

回答

9

通过添加 '-emit-LLVM -S' 你是不是生成机器码,但LLVM字节码。要运行它,你需要使用lli

由于ntvdm.exe是用于运行实模式DOS程序的虚拟机,它可能意味着windows将LLVM字节码中的可执行文件解释为16位DOS程序并尝试将其作为一个运行。

+0

非常好我明白了错误..谢谢.... –