I am learning how to use the LLVM toolchain. I have a .cpp
file, and I’m trying to compile it to an LLVM bitcode file, compile the LLVM bytecode file into an assembly file, and then assemble the assembly file into a program.
Here is the .cpp
file,
#include <iostream>
int main() {
std::cout << "Hello, world!n";
}
And here is what I am typing into the command line (taken from LLVM docs),
# Compile the C file into an LLVM bitcode file
clang -O3 -emit-llvm hello.cpp -c -o hello.bc
# Compile the program to native assembly using the LLC code generator
llc hello.bc -o hello.s
# Assemble the native assembly language file into a program
gcc hello.s -o hello.native
However, on the last step to assemble the native assembly language file into a program, I encounter this error:
hello.s: Assembler messages:
hello.s:98: Error: junk at end of line, first unrecognized character is `,'
If I follow the same steps as above but with a .c
file, the last step works and it is able to produce a hello.native
file.
I am wondering why do the above steps not work with a .cpp
file, and what do I have to do differently for .cpp
files?