
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()'std::ios_base::Init::~Init()’
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x3c): undefined reference to
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x57): undefined reference tostd::cout'std::basic_ostream<char, std::char_traits
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x63): undefined reference to>& std::operator<< <std::char_traits >(std::basic_ostream<char, std::char_traits >&, char const)’
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x70): undefined reference tostd::ostream::operator<<(int)'std::basic_ostream<char, std::char_traits
C:UsersMAGICM~1AppDataLocalTempdemo-6956e2.o:(.text+0x77): undefined reference to>& std::endl<char, std::char_traits )(std::ostream&))’>(std::basic_ostream<char, std::char_traits >&)’
C:UsersMAGICM~1AppDataLocalTempdemo-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++。




近期评论