llvm的一些知识点

How to make clang compile to LLVM IR

假定现在有C/C++文件demo.cpp

clang -S -emit-llvm demo.cpp

使用上述命令,将会生成LLVM IR文件:dmeo.ll

此外,-emit-llvm选项也可以直接传递给编译器前端,而不是通过-cc1传递给驱动程序(driver):

clang -cc1 demo.cpp -emit-llvm

一些编译问题

C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0xc): undefined reference to std::ios_base::Init::Init()'
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x3c): undefined reference to
std::ios_base::Init::~Init()’
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x57): undefined reference to std::cout'
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x63): undefined reference to
std::basic_ostream<char, std::char_traits >& std::operator<< <std::char_traits >(std::basic_ostream<char, std::char_traits >&, char const)’
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x70): undefined reference to std::ostream::operator<<(int)'
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x77): undefined reference to
std::basic_ostream<char, std::char_traits >& std::endl<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&)’
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x7f): undefined reference to `std::ostream::operator<<(std::ostream& (
)(std::ostream&))’
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)

问题出在这是C++ file,在进行编译的时候应该使用clang++