How to fix linking error for linxal crate in Rust?

Viewed 677

I tried running the example I found in the linxal crate for calculating eigenvalues, as follows:

#[macro_use]
extern crate linxal;
extern crate ndarray;

use linxal::eigenvalues::{Eigen};
use linxal::solve_linear::{SolveLinear};
use linxal::types::{c32};
use ndarray::{arr1, arr2};

fn main() {
    let m = arr2(&[[1.0f32, 2.0],
                [-2.0, 1.0]]);

    let r = Eigen::compute(&m, false, false);
    assert!(r.is_ok());

    let r = r.unwrap();
    let true_evs = arr1(&[c32::new(1.0, 2.0), c32::new(1.0, -2.0)]);
    assert_eq_within_tol!(true_evs, r.values, 0.01);

    let b = arr1(&[-1.0, 1.0]);
    let x = SolveLinear::compute(&m, &b).unwrap();
    let true_x = arr1(&[-0.6, -0.2]);
    assert_eq_within_tol!(x, true_x, 0.0001);
}

The code above panicked with the following error: = note: /usr/bin/ld: cannot find -lgfortran

So I installed gfortran and lapack: sudo apt-get install gfortran libblas-dev liblapack-dev

Now the error is different:

= note: /usr/bin/ld: /home/marcelo/dev/rust/tests/target/debug/deps/tests-8044bb79540c2a73.1gluatgbtgjkbw4v.rcgu.o: in function `lapack::c::sgeev':
        /home/marcelo/.cargo/registry/src/github.com-1ecc6299db9ec823/lapack-0.11.4/src/c.rs:1078: undefined reference to `LAPACKE_sgeev'
        /usr/bin/ld: /home/marcelo/dev/rust/tests/target/debug/deps/tests-8044bb79540c2a73.1gluatgbtgjkbw4v.rcgu.o: in function `lapack::c::sgesv':
        /home/marcelo/.cargo/registry/src/github.com-1ecc6299db9ec823/lapack-0.11.4/src/c.rs:1882: undefined reference to `LAPACKE_sgesv'
        collect2: error: ld returned 1 exit status
        
= help: 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#cargorustc-link-libkindname)

I then installed LAPACKE with the following commands, but the error message did not change.

= note: /usr/bin/ld: /home/marcelo/dev/rust/tests/target/debug/deps/tests-8044bb79540c2a73.1gluatgbtgjkbw4v.rcgu.o: in function `lapack::c::sgeev':
        /home/marcelo/.cargo/registry/src/github.com-1ecc6299db9ec823/lapack-0.11.4/src/c.rs:1078: undefined reference to `LAPACKE_sgeev'
        /usr/bin/ld: /home/marcelo/dev/rust/tests/target/debug/deps/tests-8044bb79540c2a73.1gluatgbtgjkbw4v.rcgu.o: in function `lapack::c::sgesv':
        /home/marcelo/.cargo/registry/src/github.com-1ecc6299db9ec823/lapack-0.11.4/src/c.rs:1882: undefined reference to `LAPACKE_sgesv'
        collect2: error: ld returned 1 exit status
        
= help: 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#cargorustc-link-libkindname)

The commands:

sudo apt update
sudo apt install liblapack3 
sudo apt install liblapack-dev 
sudo apt install libopenblas-base 
sudo apt install libopenblas-dev 
sudo apt install liblapacke-dev 
sudo apt install liblapack-dev

What do I have to do to make the example work? Thanks in advance!

0 Answers
Related