Cao Toan
Cao Toan

Reputation: 21

Undefined symbol LAPACKE when importing Rust lib .so into Python

I'm trying to create a simple ML library in Rust using crates like ndarray and ndarray-linalg and exploit it later in Python via ctypes. In Cargo.toml, I set crate-type = ["cdylib"]. My projet is built and works just fine in Rust but when I tried to import the output .so file into Python, it generates an error OSError: /home/Project/Lib/regression_simple/target/debug/libregression_simple.so: undefined symbol: LAPACKE_dgetri

I installed all lapack and blas necessary packages and lapacke.h can be found in /usr/include/lapacke.h

I can't seem to find any similar issue online. When I compile the Rust lib, I did see all dependencies package for ndarray-linalg loaded so I have no idea where this problem comes from.

my Cargo.toml

[lib]
name = "regression_simple"
crate-type = ["cdylib"]

[dependencies]
ndarray = { version = "0.13.0", features = ["blas"] }
ndarray-linalg = { version = "0.12.0", features = ["openblas"] }
ndarray-rand = "0.11.0"
openblas-src = {version = "0.7", features = ["system"]}
rand = "0.7.3"

Upvotes: 2

Views: 504

Answers (1)

ethanhs
ethanhs

Reputation: 1843

I ran into this on a project, and the solution was to instruct rustc to link to lapacke.

I added the following in a build.rs file.

fn main() {
    println!("cargo:rustc-link-lib=dylib=lapacke");
}

Once I did this I no longer got the undefined symbol error.

Upvotes: 0

Related Questions