-
Notifications
You must be signed in to change notification settings - Fork 4
3) Compile IR to EXE
In this chapter we want to create a exe from IR Code.
For this step you need a compiler. LLC is part of the LLVM Infrastructure. Sadly it is not delivered in the LLVM Setup. Why? I don't know.
You have two options to get LLC for Windows
-
Trust me and download my precompiled binary from : https://github.com/TimBo93/LLVM-Windows/releases/tag/v4.0.1
-
Download LLVM Sources for Windows and follow the steps to build LLC on your own.
llc -filetype=obj main.ll
now you have a linkable object file.
This is a little bit tricky. You need a linker. You can use LINK.exe from Visual Studio or you can use lld from LLVM. I recommend you to use lld for windows (lld-link).
lld-link -out:b.exe -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib\\amd64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.15063.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.15063.0\\um\\x64" -nologo main.obj
this creates a b.exe which is ready to be executed.
Where does the parameter come from? I looked how clang links object files using lld.
Just execute clang -fuse-ld=lld -v main.cpp and inspect the parameters for lld-link.