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

Compilation isue on Apple Silicon #412

Closed
ghost opened this issue Sep 8, 2021 · 5 comments
Closed

Compilation isue on Apple Silicon #412

ghost opened this issue Sep 8, 2021 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 8, 2021

I'm trying to use the tch crate for a rust project on an M1 Mac. I've successfully compiled libtorch following this tutorial. However, when I try to run a simple example of a tensor operation, I get an error that I'll paste below. However, due to the compilation of libtorch being successful I suspect that it's simply some misconfiguration on my side, but I'm not sure what exactly is wrong. In the error I see that it tries to link with the x86 version of libtorch even though I've compiled an arm version.

Error:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-arch" "arm64" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.10dj2dxtcyqmw5tt.rcgu.o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.2gpawpm4qjeegkfo.rcgu.o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.3syljxkogjj7h526.rcgu.o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.42s7946d6m4zk846.rcgu.o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.47a67b0vdngilok5.rcgu.o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.4a08k22wbezalgo6.rcgu.o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.5acw216nejx7qp1x.rcgu.o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch.3c80um9df00ieq3i.rcgu.o" "-L" "/Users/ilya/Documents/code/rust/tch/target/debug/deps" "-L" "/Users/ilya/Documents/code/rust/tch/target/debug/build/torch-sys-3d827d2c5063a974/out/libtorch/libtorch/lib" "-L" "/Users/ilya/Documents/code/rust/tch/target/debug/build/torch-sys-3d827d2c5063a974/out" "-L" "/Users/ilya/Documents/code/rust/tch/target/debug/build/bzip2-sys-33c87a67270ad180/out/lib" "-L" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libtch-c0e97b3bbf031c94.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libndarray-7fe0d61529e9e408.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libmatrixmultiply-3b1d6649965884d1.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libnum_complex-efab28a902e9383b.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libnum_integer-0542869d024cd72e.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libnum_traits-31e41211c26b224e.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/librawpointer-a917689fbcc498e1.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/librand-0d7083fa5aad3dda.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/librand_chacha-d8fa2d5d6dc5339e.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libppv_lite86-54b2ee613f6f58af.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/librand_core-cde4cc677d7ab20d.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libgetrandom-6906851871e02c71.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libhalf-22c2f70433da9e1c.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libtorch_sys-9d8a89f2b9d88131.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libzip-2a159c734ac7f6b5.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libtime-2ee0364f7ad25f09.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libbzip2-09751875dbaed745.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libbzip2_sys-320504ec5575d6ac.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libflate2-44549fc51276ef71.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libminiz_oxide-c084e715820ee2b7.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libadler-b09299ada5766b19.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libbyteorder-deb4cdec9edf3423.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libcrc32fast-b3a0ad7c02cf0836.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libcfg_if-d671fa1fded512d8.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/libthiserror-8bdaaf1be52e4e27.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/liblibc-6abf360a4d6c9807.rlib" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/liblazy_static-0bec3fe2b8b83b67.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libstd-4f3db8e36d6808c7.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-2e47ff55cbd86a0a.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libobject-25f436cb9eb82ebb.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-4e7d7b243ae048e3.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libgimli-7e54d81aafaeb44b.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-6ae3db8c217289fa.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-2e120d9f4d6c3f33.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-b5fdda194088833c.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-70cb89b6f32ee98c.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libunwind-f759054bddd1dae6.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-12d13dc83b6cac9b.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/liblibc-cd153af057c88257.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/liballoc-8b71f11b60422053.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-dc5db2696e47717b.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libcore-5b7547715b4a5938.rlib" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-636047e37365b2cb.rlib" "-lc++" "-ltorch" "-ltorch_cpu" "-lc10" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/opt/homebrew/Cellar/rust/1.54.0_1/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/ilya/Documents/code/rust/tch/target/debug/deps/tch" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: warning: ignoring file /Users/ilya/Documents/code/rust/tch/target/debug/build/torch-sys-3d827d2c5063a974/out/libtorch/libtorch/lib/libc10.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
          ld: warning: ignoring file /Users/ilya/Documents/code/rust/tch/target/debug/build/torch-sys-3d827d2c5063a974/out/libtorch/libtorch/lib/libtorch.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
          ld: warning: ignoring file /Users/ilya/Documents/code/rust/tch/target/debug/build/torch-sys-3d827d2c5063a974/out/libtorch/libtorch/lib/libtorch_cpu.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
          Undefined symbols for architecture arm64:
            "c10::impl::ExcludeDispatchKeyGuard::~ExcludeDispatchKeyGuard()", referenced from:
                at::AutoDispatchBelowADInplaceOrView::~AutoDispatchBelowADInplaceOrView() in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "c10::impl::ExcludeDispatchKeyGuard::ExcludeDispatchKeyGuard(c10::DispatchKeySet)", referenced from:
                at::AutoDispatchBelowADInplaceOrView::AutoDispatchBelowADInplaceOrView() in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "vtable for torch::autograd::AutogradMeta", referenced from:
                torch::autograd::AutogradMeta::AutogradMeta(c10::TensorImpl*, bool, torch::autograd::Edge) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
            "c10::AutogradMetaInterface::~AutogradMetaInterface()", referenced from:
                torch::autograd::AutogradMeta::AutogradMeta(c10::TensorImpl*, bool, torch::autograd::Edge) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "caffe2::TypeMeta::typeMetaDatas()", referenced from:
                caffe2::TypeMeta::data() const in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "c10::TensorImpl::set_autograd_meta(std::__1::unique_ptr<c10::AutogradMetaInterface, std::__1::default_delete<c10::AutogradMetaInterface> >)", referenced from:
                torch::autograd::make_variable(at::Tensor, bool, bool) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "c10::UndefinedTensorImpl::_singleton", referenced from:
                c10::UndefinedTensorImpl::singleton() in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "c10::detail::torchInternalAssertFail(char const*, char const*, unsigned int, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
                c10::Device::validate() in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
                caffe2::TypeMeta::fromScalarType(c10::ScalarType) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "at::mul(at::Tensor const&, c10::Scalar const&)", referenced from:
                _atg_mul_scalar in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "c10::detail::torchInternalAssertFail(char const*, char const*, unsigned int, char const*, char const*)", referenced from:
                c10::intrusive_ptr<c10::VariableVersion::VersionCounter, c10::detail::intrusive_target_default_null_type<c10::VariableVersion::VersionCounter> >::intrusive_ptr(c10::VariableVersion::VersionCounter*) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
                c10::intrusive_ptr_target::~intrusive_ptr_target() in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
                c10::intrusive_ptr<c10::TensorImpl, c10::UndefinedTensorImpl>::retain_() in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "vtable for c10::AutogradMetaInterface", referenced from:
                c10::AutogradMetaInterface::AutogradMetaInterface() in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
            "c10::detail::torchCheckFail(char const*, char const*, unsigned int, char const*)", referenced from:
                torch::autograd::AutogradMeta::AutogradMeta(c10::TensorImpl*, bool, torch::autograd::Edge) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
                c10::detail::torchInternalAssertFail(char const*, char const*, unsigned int, char const*, c10::detail::CompileTimeEmptyString) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
                c10::TensorImpl::itemsize() const in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
                c10::TensorImpl::data() const in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "at::print(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, at::Tensor const&, long long)", referenced from:
                at::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, at::Tensor const&) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
            "at::zeros(c10::ArrayRef<long long>, c10::TensorOptions)", referenced from:
                torch::zeros(c10::ArrayRef<long long>, c10::TensorOptions) in libtorch_sys-9d8a89f2b9d88131.rlib(torch_api.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: aborting due to previous error

error: could not compile `tch`

To learn more, run the command again with --verbose.
@lawrenceadams
Copy link

Same issue

@LaurentMazare
Copy link
Owner

I don't have a M1 mac so cannot really test but I think there are some indications on how to get this to work in #346.

@raphaelmenges
Copy link

I am still facing the very same issue. Did anyone find a solution?

@oersted
Copy link

oersted commented Oct 25, 2022

This might help #488

@LaurentMazare
Copy link
Owner

Closing this in favor of #488

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

4 participants