rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.76k stars 2.42k forks source link

dynamic link c lib openblas error #9984

Closed franklucky001 closed 3 years ago

franklucky001 commented 3 years ago

Problem

First, i install openblas and lapack by brew

brew install openblas brew install lapack

when i use openblas-src with features ["cblas", "system"], i set RUSTFLAGS in project/.cargo/config.toml

case 1

  • set env in ~/.bash_profile
    export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openblas/lib"
    export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/opt/openblas/lib"
    export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/lapack/lib"
    export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/opt/lapack/lib"

    run cargo test
    i get error of libBLAS (with env of library openblas) dyld: Library not loaded: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib Referenced from: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib Reason: Incompatible library version: vecLib requires version 1.0.0 or later, but libBLAS.dylib provides version 0.0.0

    or error of libvDSP (with env of library of lapack) dyld: Symbol not found: _cblas_dgemm Referenced from: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib Expected in: /usr/local/opt/lapack/lib/libBLAS.dylib in /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib

case 2

warning: preprocessing_contrib (lib test) generated 6 warnings (6 duplicates) error: could not compile preprocessing_contrib due to previous error; 6 warnings emitted

Caused by: process didn't exit successfully: rustc --crate-name preprocessing_contrib --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --test -C metadata=afa4a0be7d6ff698 -C extra-filename=-afa4a0be7d6ff698 --out-dir /Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps -C incremental=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/incremental -L dependency=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps --extern blas_src=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/libblas_src-9d74ad231a46e048.rlib --extern linfa=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/liblinfa-cb3ffd43d6b8eaa2.rlib --extern linfa_preprocessing=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/liblinfa_preprocessing-0a776c26ed2cfa7f.rlib --extern ndarray=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/libndarray-556145df8dd460d1.rlib --extern openblas_src=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/libopenblas_src-fc8092715b5adcea.rlib '-L /usr/local/opt/openblas/lib' '-L /usr/local/opt/lapack/lib' -L /usr/local/opt/openblas/lib (exit status: 1)


case 3

warning: preprocessing_contrib (lib test) generated 6 warnings (6 duplicates) error: could not compile preprocessing_contrib due to previous error; 6 warnings emitted

Caused by: process didn't exit successfully: `rustc --crate-name preprocessing_contrib --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 --test -C metadata=afa4a0be7d6ff698 -C extra-filename=-afa4a0be7d6ff698 --out-dir /Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps -C incremental=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/incremental -L dependency=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps --extern blas_src=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/libblas_src-9d74ad231a46e048.rlib --extern linfa=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/liblinfa-cb3ffd43d6b8eaa2.rlib --extern linfa_preprocessing=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/liblinfa_preprocessing-0a776c26ed2cfa7f.rlib --extern ndarray=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/libndarray-556145df8dd460d1.rlib --extern openblas_src=/Users/frankguo/workspace/rust/preprocessing_contrib/target/debug/deps/libopenblas_src-fc8092715b5adcea.rlib


more information

See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies] ndarray = { version = "0.14",default-features = false, features = ["blas"] } ndarray-linalg = { version = "0.13", optional = true } blas-src = { version = "0.8", features = ["openblas"] } openblas-src = { version = "0.10", features = ["cblas", "system"] } linfa = {version = "0.4.0", features = ["openblas-system"]} linfa-preprocessing = {version = "0.4.0"}


- source code `lib.rs`
```rust
mod encoders{
    use linfa::dataset::{AsTargets, DatasetBase, Float, WithLapack, WithoutLapack};
    use linfa::traits::Transformer;
    use linfa_preprocessing::norm_scaling::NormScaler;
    use ndarray::{Array2, ArrayBase, Data, Ix2};

    pub struct Binarizer<T>{
        threshold: T,
    }

    impl<T: Float> Binarizer<T> {
        fn new(threshold: T) -> Self{
            Self{
                threshold
            }
        }
    }

    impl <T: Float> Default for Binarizer<T> {
        fn default() -> Self {
            Self{
                threshold: T::from_f64(0.0).unwrap()
            }
        }
    }

    impl<F: Float> Transformer<Array2<F>, Array2<F>> for Binarizer<F> {
        fn transform(&self, x: Array2<F>) -> Array2<F> {
            todo!()
        }
    }

    impl<F: Float, D: Data<Elem = F>, T: AsTargets>
        Transformer<DatasetBase<ArrayBase<D, Ix2>, T>, DatasetBase<Array2<F>, T>> for Binarizer<F>{
        fn transform(&self, x: DatasetBase<ArrayBase<D, Ix2>, T>) -> DatasetBase<Array2<F>, T> {
            todo!()
        }
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

How can I solve this problem ? How to use crate openblas-src link system's openblas dynamic library in rust ?

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

ehuss commented 3 years ago

It seems like you are having trouble with not having liblapacke installed. This does not appear to be an issue with cargo, may I recommend you try one of the user forums for help, or ask on the openblas-src repository? We cannot help with building and installing third-party packages.

ehuss commented 3 years ago

Closing as this doesn't appear to be an issue with cargo specifically. Hopefully you can find some help in one of the avenues mentioned above.