运行使用rustc生成的LLVM文件,使用clang

时间:2018-01-24 19:23:18

标签: rust llvm llvm-clang

我尝试使用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}}命令行参数,并尝试使用它但无济于事。

0 个答案:

没有答案