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

Accelerate Linkage Failure -- without explicit linkage in build.rs #22

Open
ethanmsl opened this issue Dec 17, 2023 · 1 comment
Open

Comments

@ethanmsl
Copy link

General Description:

The accelerate libary fails to link, despite correct dependency and feature specification. Clonable minmial repo example below.
For a simple crate, addition of a build.rs script explicitely linking the library seems to fix this ("cargo:rustc-link-lib=framework=Accelerate").

Exception:

However, not show below, I was not able to fix this problem with a build-script for a Workspace based repo.

Minimal Repo Example:

  • accelerate-test
  • you can clone and just disable/enable the build-rs script. (Or I can, I don't know if this is universal.)

Error on build:

error: linking with `cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="
...
"
  = note: ld: Undefined symbols:
            _cblas_cgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
            _cblas_dgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
            _cblas_sgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
            _cblas_zgemm, referenced from:
                ndarray::linalg::impl_linalg::mat_mul_impl::ha5aa880a642f660e in accelerate_test-df9792214fc029cd.4wf4kx2jc5a77go6.rcgu.o
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `accelerate-test` (bin "accelerate-test") due to previous error

Caused by:
  process didn't exit successfully: `/Users/username/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name accelerate_test --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=181 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=df9792214fc029cd -C extra-filename=-df9792214fc029cd --out-dir /Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps -C incremental=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/incremental -L dependency=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps --extern blas_src=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps/libblas_src-8261a14688e7d167.rlib --extern ndarray=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps/libndarray-cebad4e9c98c9d7b.rlib --extern ndarray_linalg=/Users/username/Documents/Programming_Dirs/Rust/accelerate-test/target/debug/deps/libndarray_linalg-435cbc831f01e25f.rlib` (exit status: 1)

System & Cargo information:

  • cargo 1.74.1 (ecb9851af 2023-10-18)
  • Apple M2 Max
  • macOS Sonoma (14.2)
@astraw
Copy link
Member

astraw commented Dec 18, 2023

Thanks for the report. I confirm the same behavior on my machine. The accelerate-src crate does print "cargo:rustc-link-lib=framework=Accelerate" but with recent Rust versions, this linker arg isn't getting picked when building the binary. This transitive setting of linker args by dependencies previously worked but was unintentional and has been discontinued. So you would indeed need to set linker args in the final binary.

Ideally blas-src and accelerate-src should make this as easy as possible, e.g. by implementing and documenting use of the DEP_ environment variables and this mechanism.

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

No branches or pull requests

2 participants