使用build.rs显式配置仍无法链接ARPACK C库问题排查
问题:Rust链接本地ARPACK静态库失败
背景
已完成ARPACK的编译,生成了静态库文件libarpack.a,并编写了对应的build.rs用于配置Cargo链接该库:
use std::env; use std::path::Path; fn main() { // 获取包含Cargo.toml的工作区根目录路径 let workspace_root = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); // 定义相对于工作区根目录的本地库路径 let lib_path = Path::new(&workspace_root).join("arpack-ng/build/"); println!("cargo:warning={}", lib_path.display()); // 告知Cargo查找本地库的路径及链接静态库 println!("cargo:rustc-link-search=native={}", lib_path.display()); println!("cargo:rustc-link-lib=static=arpack"); }
编译错误
执行编译时出现链接器未定义引用错误:
= note: /usr/bin/ld: /home/makogan/rust_never_engine/crates/algebra/target/debug/deps/algebra-8ab0fc9a1c48e81c.8q7c32k90oqy6djs87syi3nmg.rcgu.o: in function `algebra::eigen_decomposition::faer_arpack_symmetric_f64': /home/makogan/rust_never_engine/crates/algebra/src/eigen_decomposition.rs:150:(.text._ZN7algebra19eigen_decomposition25faer_arpack_symmetric_f6417h42c779a97fe8f680E+0xa27): undefined reference to `dsaupd_c' /usr/bin/ld: /home/makogan/rust_never_engine/crates/algebra/src/eigen_decomposition.rs:199:(.text._ZN7algebra19eigen_decomposition25faer_arpack_symmetric_f6417h42c779a97fe8f680E+0x2b7d): undefined reference to `dseupd_c' collect2: error: ld returned 1 exit status = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified = note: use the `-l` flag to specify native libraries to link = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib) The following warnings were emitted during compilation: warning: algebra@0.1.0: /home/makogan/rust_never_engine/crates/algebra/arpack-ng/build/
已排查情况
- 确认
libarpack.a存在于build.rs指定的路径中,路径配置无误 - 检查静态库符号后发现,库中仅存在
dsaupd_符号,而非代码中引用的dsaupd_c - 启用ICB选项重新编译ARPACK后,链接时又出现
libgfortran相关符号缺失的问题
内容的提问来源于stack exchange,提问作者Makogan
相关产品推荐
相关产品推荐

