Running LLVM file, generated with rustc, with clang

守給你的承諾、 提交于 2019-12-10 16:24:14

问题


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.

来源:https://stackoverflow.com/questions/48430136/running-llvm-file-generated-with-rustc-with-clang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!