I'm trying to run a .ll file with clang and getting linker errors. I have a file test.rs that simply includes a main function with a println! statement. I generate the LLVM IR with the command rustc --emit=llvm-ir --crate-type=bin test.rs. When I try to run the output test.ll file with clang test.ll I get a linker error:
Undefined symbols for architecture x86_64:
"std::io::stdio::_print::h178318b95760562a", referenced from:
rust_test::main::h84a9713c734a1b45 in rust_test-9ea667.o
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So I figured clang couldn't find the Rust libraries and attempted to provide a path to them with the command clang -L$HOME/.rustup/toolchains/<arch>/lib test.ll but I receive the same error.
The goal here is to create a couple functions in Rust that I will call from LLVM, so I'll have a custom file.ll that will use functions that the Rust LLVM IR will provide. I noticed that rustc has a crate-type command-line argument called staticlib and tried to use that as well but to no avail.