【问题标题】:Linking Rust to LLVM API in Cargo.toml在 Cargo.toml 中将 Rust 链接到 LLVM API
【发布时间】:2021-11-22 17:46:03
【问题描述】:

我正在使用一个包装 LLVM-C API (inkwell) 的库,因此我需要将我的 Rust 二进制文件链接到 LLVM 库。如果我导出以下锈标记:

export RUSTFLAGS=-lLLVM-12 -lm -ldl -lc -lpthread -lutil -lgcc_s -C link-args=-L/usr/lib/llvm/12/lib64

然后编译运行正常。

如果我随后将这些行插入到我的项目的Cargo.toml 文件中:

[build]
rustflags = ["-lLLVM-12", "-lm","-ldl","-lc","-lpthread","-lutil","-lgcc_s", "-C", "link-args=-L/usr/lib/llvm/12/lib64"]

然后我得到针对 LLVM-C 函数的链接错误。

为什么这适用于环境变量,但不适用于我的货物配置文件?我是否正在以某种方式配置货物?

【问题讨论】:

  • 不确定这是否是问题所在,但AFAIK rustflags 是通过config.toml 配置的,而不是Cargo.toml - doc.rust-lang.org/cargo/reference/config.html
  • 这解决了,谢谢。如果您愿意,可以添加回复让我标记为已解决。

标签: rust linker llvm rust-cargo


【解决方案1】:

根据Cargo documentationrustflags 属性通过.cargo/config.toml 记录,而不是Cargo.toml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 2021-12-27
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多