Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic link c lib openblas error #79

Open
franklucky001 opened this issue Oct 21, 2021 · 0 comments
Open

dynamic link c lib openblas error #79

franklucky001 opened this issue Oct 21, 2021 · 0 comments

Comments

@franklucky001
Copy link

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

  • comment out env of both openblas and lapack 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 got error compile error

= note: ld: warning: directory not found for option '-L /usr/local/opt/openblas/lib'
ld: warning: directory not found for option '-L /usr/local/opt/lapack/lib'
ld: library not found for -llapacke
clang: error: linker command failed with exit code 1 (use -v to see invocation)

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

  • clear RUSTFLAGS in project/.cargo/config.toml
    run cargo test
    i got compile error

= note: ld: library not found for -llapacke
clang: error: linker command failed with exit code 1 (use -v to see invocation)

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

  • toolchains

stable-x86_64-apple-darwin (default)
rustc 1.55.0 (c8dfcfe04 2021-09-06)
cargo 1.55.0 (32da73ab1 2021-08-23)

  • config.toml
[target.x86_64-apple-darwin]
rustflags = ["-L /usr/local/opt/openblas/lib", "-L /usr/local/opt/lapack/lib"]  # custom flags for `rustc`

project file Cargo.toml

[package]
name = "preprocessing_contrib"
version = "0.1.0"
edition = "2018"

# 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
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

  • toolchains

stable-x86_64-apple-darwin (default)
rustc 1.55.0 (c8dfcfe04 2021-09-06)
cargo 1.55.0 (32da73ab1 2021-08-23)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants