rust - 无法添加到依赖项的 rustc-link-search 路径

标签 rust rust-cargo

我正在尝试使用 cassandra-rs 构建测试应用程序它使用 DataStax CPP driver .我正在使用 cargo 0.6.0 (ec9398e 2015-09-29)(从 gi​​t 构建)

我的 DataStax 驱动程序不在 Cargo 查找的标准目录中。

我添加了一个构建脚本,指定了 DataStax 驱动程序的路径:

fn main() {
    println!("cargo:rustc-link-search={}", "/path/to/dir/");
}

这是我的 Cargo.toml:

[package]
name = "castest"
version = "0.1.0"
build = "build.rs"

[dependencies]
cassandra="*"

但是 cargo build --verbose 显示构建时不包含额外的搜索目录。

构建实际上失败的包是 cql_bindgen,它是 cassandra-rs 的依赖项。在那个项目中有这个 build.rs:

fn main() {
    println!("cargo:rustc-flags=-l dylib=crypto");
    println!("cargo:rustc-flags=-l dylib=ssl");
    println!("cargo:rustc-flags=-l dylib=stdc++");
    println!("cargo:rustc-flags=-l dylib=uv");
    println!("cargo:rustc-link-search={}", "/usr/lib/");
    println!("cargo:rustc-link-search={}", "/usr/local/lib64");
    println!("cargo:rustc-link-lib=static=cassandra_static");
}

如何在我的项目中添加额外的库或以其他方式覆盖在依赖项目中设置的配置?

最佳答案

除了 features 之外,crate 的下游用户无法更改该 crate 的编译方式。箱子暴露出来。

当链接到现有的原生库时,Cargo build script用于帮助找到要链接到的适当库。

此处正确的解决方案是修复上游 crate (cql_bindgen) build.rs允许最终用户指定要在其中搜索的备用路径。一种方法是使用 option_env!宏,类似于:

if let Some(datastax_dir) = option_env!("CQL_BINDGEN_DATASTAX_LIB_PATH") {
    println!("cargo:rustc-link-search={}", datastax_dir);
}

当然可以override the dependency在迭代时使用本地版本以获得适用于本地的解决方案。

与此同时,您可以尝试将您的库安装在已搜索到的硬编码目录之一中。

关于rust - 无法添加到依赖项的 rustc-link-search 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32861808/

相关文章:

file-io - 打开文件返回ErrorKind::Other 'Error: Os, code: 20, message: “Not a directory”'

rust - 是否可以将 char 与 &char 或 &mut char 进行比较?

rust - 如何使用 Assembly (NASM) 引导加载程序编译 Rust 内核

installation - "error: specified package has no binaries"尝试安装带有 cargo 的包时?

string - Rust 中的 `str` 有什么用处吗?

generics - 如何调用许多不同类型的函数?

rust - 是否可以使用相同的文件进行读写?

rust - 如何正确引用相同的代码作为依赖项的依赖项?

rust - 如何通过命令行指定库的输出文件名?

rust - 是否可以在工作区中运行 `cargo watch`?