Hello! I'm building my toy compiler with Cranelift as my backend.
I'm getting binary format unknown error with the following command (tried this command on both Linux and MacOS):
$ clif-util compile --target x86_64 -o test.o filetests/main.clif
Error: Backend error: binary format is unknown
Caused by:
binary format is unknown
// main.clif
test run
target x86_64
function %main() -> i32 {
block0:
v0 = iconst.i32 42
return v0
}
; print: %main()
; run: %main() == 4
Can anyone give me some hints for this issue? Both clif-util test
and clif-util run
can execute perfectly.
Right now, I'm thinking to compile Cranelift IR into object file, and then link it with dynamic library with gcc, so that I can get an executable. Or maybe there are alternatives to achieve this goal? Thanks in advanced!
Lee Wei has marked this topic as resolved.
Lee Wei has marked this topic as unresolved.
You need to specify the full target I think rather than just the architecture. Otherwise it wouldn't know if the correct object file format to use should be ELF, Mach-O or COFF. Try clif-util compile --target x86_64-apple-darwin -o test.o filetests/main.clif
if you want a Mach-O object file.
On linux you did use x86_64-unknown-linux-gnu
as target.
@Lee Wei
@bjorn3 Thanks! It worked!
Lee Wei has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC