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

Vin*_*ddy 5 c++ compiler-construction llvm clang

#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;
}
Run Code Online (Sandbox Code Playgroud)

当我们编译上面的代码时

clang++ test.cc -o a.exe
Run Code Online (Sandbox Code Playgroud)

并运行一个完美的程序.但是当我们编译同一个程序时

clang++ test.cc -emit-llvm -S -o a.exe
Run Code Online (Sandbox Code Playgroud)

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

软件堆栈:

clang version 2.9 (tags/RELEASE_29/final)
Target: i386-pc-mingw32
Thread model: posix
Run Code Online (Sandbox Code Playgroud)

pla*_*aes 9

通过添加'-emit-llvm -S',您不会生成机器代码,而是生成LLVM字节码.要运行它,您需要使用lli.

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