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:\Users\MAGICM~1\AppData\Local\Temp\demo-6956e2.o:(.text+0xc): undefined reference to
std::ios_base::Init::Init()' C:\Users\MAGICM~1\AppData\Local\Temp\demo-6956e2.o:(.text+0x3c): undefined reference to
std::ios_base::Init::~Init()’
C:\Users\MAGICM~1\AppData\Local\Temp\demo-6956e2.o:(.text+0x57): undefined reference tostd::cout' C:\Users\MAGICM~1\AppData\Local\Temp\demo-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:\Users\MAGICM~1\AppData\Local\Temp\demo-6956e2.o:(.text+0x70): undefined reference tostd::ostream::operator<<(int)' C:\Users\MAGICM~1\AppData\Local\Temp\demo-6956e2.o:(.text+0x77): undefined reference to
std::basic_ostream<char, std::char_traits>& std::endl<char, std::char_traits )(std::ostream&))’>(std::basic_ostream<char, std::char_traits >&)’
C:\Users\MAGICM~1\AppData\Local\Temp\demo-6956e2.o:(.text+0x7f): undefined reference to `std::ostream::operator<<(std::ostream& (
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
问题出在这是C++ file,在进行编译的时候应该使用clang++
。