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

macOS High Sierra Linking Fails #120

Closed
bbrener1 opened this issue Oct 8, 2018 · 4 comments
Closed

macOS High Sierra Linking Fails #120

bbrener1 opened this issue Oct 8, 2018 · 4 comments

Comments

@bbrener1
Copy link

bbrener1 commented Oct 8, 2018

Encountering problems when building with ndarray-linalg as a dependency

Versions:

OSX: 10.13.4 (17E199)

clang: Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

blas and openblas installed via conda, versions are:

blas 1.0 openblas anaconda
openblas 0.3.3 3 anaconda
openblas-devel 0.3.3 3 anaconda

gfortran was installed via homebrew:

boris@Boriss-MacBook-Pro-2:~/haxx/python/gravity_clustering$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/8.2.0/libexec/gcc/x86_64-apple-darwin17.7.0/8.2.0/lto-wrapper
Target: x86_64-apple-darwin17.7.0
Configured with: ../configure --build=x86_64-apple-darwin17.7.0 --prefix=/usr/local/Cellar/gcc/8.2.0 --libdir=/usr/local/Cellar/gcc/8.2.0/lib/gcc/8 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-8 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-checking=release --with-pkgversion='Homebrew GCC 8.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-nls
Thread model: posix
gcc version 8.2.0 (Homebrew GCC 8.2.0)

Error text is as follows:

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering0-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering1-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering10-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering11-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering12-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering13-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering14-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering15-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering2-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering3-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering4-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering5-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering6-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering7-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering8-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.gravity_clustering9-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o" "-o" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/gravity_clustering-af9a185107b464a2.crate.allocator.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/boris/haxx/python/gravity_clustering/target/release/deps" "-L" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/librayon-4b02d786d1bd55a5.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/librayon_core-6ad42d4bfe037261.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libcrossbeam_deque-3e4d4acc829c5c73.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libcrossbeam_epoch-ca8363f9197e111f.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libscopeguard-b6ce87978007c9eb.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libmemoffset-19ba1fa21caf0388.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/liblazy_static-f9f2f60147bdfdf0.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libcrossbeam_utils-025f80d9e0908a5b.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libcfg_if-31e57d1f0d09db98.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libarrayvec-b72cb89b05274aca.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libnodrop-a40abb48bf76c4e6.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libndarray_linalg-b74f9ca68324d40e.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/liblapacke-4b6143a9e09368de.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/liblapacke_sys-fa7f00acac0e1073.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libndarray-9ae38c327d6212ae.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libnum_complex-e1f6eb9ac6503af6.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libnum_traits-03eef3ab8946d374.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libitertools-9016f082db60a7a7.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libeither-fcfc96e5a4db8cce.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libmatrixmultiply-817168ed32bf0403.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/librawpointer-d8a37321df43ac4b.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libblas_src-772e556da810a4d4.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libcblas_sys-9a2f33c41b92c395.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/libnum_cpus-eaf59e66f6f31242.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/librand-800929ac40d24603.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/liblibc-3c1946dd65acb4d1.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/librand_core-3b99e0cebd545167.rlib" "/Users/boris/haxx/python/gravity_clustering/target/release/deps/librand_core-d541ebf4a966e2be.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-03b901326ae24853.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-6ff7c563e703aab0.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-5bcc251fd166dc12.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-3af07b1997da2eea.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_system-f2d882c31340c020.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-c27b8d1b261d1a71.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-a8adffd320893f05.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-095d0e0c6f534dd1.rlib" "/Users/boris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-5bd49e510cc11ed9.rlib" "-framework" "Security" "-lSystem" "-lresolv" "-lpthread" "-lc" "-lm"
  = note: Undefined symbols for architecture x86_64:
            "_LAPACKE_dgesvd", referenced from:
                _$LT$f64$u20$as$u20$ndarray_linalg..lapack_traits..svd..SVD_$GT$::svd::hfaf0e8598dff5bc2 in libndarray_linalg-b74f9ca68324d40e.rlib(ndarray_linalg-b74f9ca68324d40e.ndarray_linalg4-18283fb439679ae1ca7e2ec2221088bb.rs.rcgu.o)
            "_cblas_ddot", referenced from:
                ndarray::linalg::impl_linalg::_$LT$impl$u20$ndarray..ArrayBase$LT$S$C$$u20$ndarray..dimension..dim..Dim$LT$$u5b$usize$u3b$$u20$_$u5d$$GT$$GT$$GT$::dot::h714423fc9780e798 in gravity_clustering-af9a185107b464a2.gravity_clustering1-b7d3c0d45745af024f0794934bb8388b.rs.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Cargo.toml is:

[package]
name = "gravity_clustering"
version = "0.1.0"
authors = ["boris"]

[dependencies]
ndarray = "0.12"
ndarray-linalg = { version = "0.10", features = ["openblas"] }
#(I have tried this with "ndarray-linalg = "0.10"" as well)
rand = "0.5.5"
num_cpus = "1.8.0"
rayon = "1.0.2"

Please advise on options, so far I have solved this by creating a symlink in usr/local/bin for cc to link to G++-8, however this is terrifying and terrible, and I would like another way to solve. Issue doesn't appear to be platform dependent, as this build also fails on Ubuntu.

EDIT(by @termoshtt): Fix markdown

@termoshtt
Copy link
Member

The feature "openblas" builds OpenBLAS in a temporal directory, which is not match for your use case. To link existing library, please link backend LAPACK library using openblas-src = { version = "*", features = ["system"]}.

@bbrener1
Copy link
Author

bbrener1 commented Oct 18, 2018

I think I might be running into the issue noted here:
rust-lang/cargo#2888

I have produced a very minimal crate for which I have not been able to resolve compilation issues:

https://github.com/bbrener1/dylib_linking_test

Briefly, these are the only contents of the crate:

Cargo.toml:

[package]
name = "n_test"
version = "0.1.0"
authors = ["boris"]

[dependencies]
ndarray = "0.12"
#ndarray-linalg = { version = "0.10" }
ndarray-linalg = { version = "0.10", features = ["openblas"] }
#ndarray-linalg = { version = "0.10", features = ["intel-mkl"] }
openblas-src = { version = "0.6", features = ["system"] }
#intel-mkl-src = "0.2.5"
#blas = "*"
#netlib-src = { version = "0.6" }

src/main.rs:

extern crate ndarray;
extern crate ndarray_linalg;
// extern crate blas;
// extern crate netlib_src;
extern crate openblas_src;
// extern crate intel_mkl_src;

use ndarray::{Array,Ix2};
use ndarray_linalg::{Factorize,Inverse};

fn main() {

    let mut mtx: Array<f64,Ix2> = Array::from_shape_vec((2,2),vec![1.,2.,3.,4.]).unwrap();
    mtx.factorize().unwrap().inv();

    println!("Hello, world!");

}

Currently this returns the following error:

error: could not find native static library `openblas`, perhaps an -L flag is missing?

error: aborting due to previous error

error: Could not compile `openblas-src`.

To learn more, run the command again with --verbose.

Perhaps this is occurring because openblas is installed in ~/miniconda3/pkgs/... and cargo is changing LD_LIBRARY_PATH ?

I suspect this is the case because when I reconfigure this same crate to instead use intel-mkl-src, it compiles successfully, and moreover executes successfully using cargo run. However, if the executable itself is called, an error is returned stating

dyld: Library not loaded: @rpath/libmkl_intel_lp64.dylib
  Referenced from: /Users/boris/haxx/ndarray_linalg_test/dylib_linking_test/./target/debug/n_test
  Reason: image not found
Abort trap: 6

Thank you for your help


EDIT (by @termoshtt): Fix markdown

@termoshtt
Copy link
Member

ndarray-linalg = { version = "0.10", features = ["openblas"] }

Please drop this feature

ndarray-linalg = { version = "0.10" }

Perhaps this is occurring because openblas is installed in ~/miniconda3/pkgs/... and cargo is changing LD_LIBRARY_PATH ?

Please add the library path in miniconda both LIBRARY_PATH and LD_LIBRARY_PATH. cargo build -vv will display the full link command, and the -L flag in it will help your debug.

@termoshtt
Copy link
Member

Please reopen if not resolved

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

No branches or pull requests

2 participants