Getting LibTorch to work

I was following the guide on https://pytorch.org/cppdocs/installing.html

When running the make command I get the following errors;

make -j4
[ 50%] Linking CXX executable example-app
ld: warning: ignoring file /Users/axl/Documents/pytorch/libtorch/lib/libtorch.so, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /Users/axl/Documents/pytorch/libtorch/lib/libtorch.so
ld: warning: ignoring file /Users/axl/Documents/pytorch/libtorch/lib/libcaffe2.so, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /Users/axl/Documents/pytorch/libtorch/lib/libcaffe2.so
ld: warning: ignoring file /Users/axl/Documents/pytorch/libtorch/lib/libc10.so, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /Users/axl/Documents/pytorch/libtorch/lib/libc10.so
Undefined symbols for architecture x86_64:
  "at::UndefinedTensorImpl::_singleton", referenced from:
      at::UndefinedTensorImpl::singleton() in main.cpp.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 main.cpp.o
  "at::native::rand(c10::ArrayRef<long long>, c10::TensorOptions const&)", referenced from:
      at::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "c10::impl::device_guard_impl_registry", referenced from:
      c10::impl::getDeviceGuardImpl(c10::DeviceType) in main.cpp.o
  "c10::Error::Error(c10::SourceLocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      torch::autograd::make_variable(at::Tensor, bool) in main.cpp.o
      torch::jit::Block::appendNode(torch::jit::Node*) in main.cpp.o
      torch::jit::Node::inBlockList() const in main.cpp.o
      c10::impl::getDeviceGuardImpl(c10::DeviceType) in main.cpp.o
      c10::intrusive_ptr<at::TensorImpl, at::UndefinedTensorImpl>::retain_() in main.cpp.o
  "c10::Device::validate()", referenced from:
      c10::Device::Device(c10::DeviceType, short) in main.cpp.o
  "c10::Symbol::fromQualString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "c10::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, c10::DeviceType)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& c10::detail::_str<c10::DeviceType>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, c10::DeviceType const&) in main.cpp.o
  "torch::jit::Node::insertBefore(torch::jit::Node*)", referenced from:
      torch::jit::Block::appendNode(torch::jit::Node*) in main.cpp.o
  "torch::jit::Graph::create(c10::Symbol, unsigned long)", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "torch::jit::tracer::getTracingState()", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
      torch::jit::tracer::isTracing() in main.cpp.o
  "torch::jit::tracer::setTracingState(std::__1::shared_ptr<torch::jit::tracer::TracingState>)", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "torch::jit::tracer::recordSourceLocation(torch::jit::Node*)", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "torch::jit::tracer::addInputs(torch::jit::Node*, char const*, c10::ArrayRef<long long>)", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "torch::jit::tracer::addInputs(torch::jit::Node*, char const*, c10::TensorOptions const&)", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "torch::jit::tracer::addOutput(torch::jit::Node*, at::Tensor const&)", referenced from:
      torch::rand(c10::ArrayRef<long long>, c10::TensorOptions const&) in main.cpp.o
  "torch::autograd::Variable::Impl::Impl(at::Tensor, bool, torch::autograd::Edge)", referenced from:
      c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> > c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> >::make<at::Tensor&, bool&>(at::Tensor&&&, bool&&&) in main.cpp.o
  "caffe2::detail::_typeMetaDataInstance_preallocated_6", referenced from:
      caffe2::detail::TypeMetaData const* caffe2::TypeMeta::_typeMetaDataInstance<float>() in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [example-app] Error 1
make[1]: *** [CMakeFiles/example-app.dir/all] Error 2
make: *** [all] Error 2
1 Like