我尝试使用clang运行.ll
文件并获取链接器错误。我有一个文件test.rs
,它只包含一个带有println!
语句的主函数。我使用命令rustc --emit=llvm-ir --crate-type=bin test.rs
生成LLVM IR。当我尝试使用test.ll
运行输出clang test.ll
文件时,我收到链接器错误:
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)
所以我认为clang找不到Rust库并尝试使用命令clang -L$HOME/.rustup/toolchains/<arch>/lib test.ll
为它们提供路径,但我收到同样的错误。
这里的目标是在Rust中创建一些我将从LLVM调用的函数,因此我将使用一个自定义file.ll
来使用Rust LLVM IR将提供的函数。我注意到rustc
有一个名为crate-type
的{{1}}命令行参数,并尝试使用它但无济于事。