Xcode and LibTorch on Apple M1 Silicon

I'm trying to learn Xcode and iOS development with swift. I'm going through the PyTorch tutorial
to configure the Xcode env and I'm unable to get it working.
Specifically I'm just doing the simple helloWorld project. The
installation of the libraries seems to have gone fine as has the pytorch
pod install command.

However when I try to build, it fails with this error:

Code Block
ld: in /Users/user/Development/mobileTorch/ios-demo-app/HelloWorld/HelloWorld/Pods/LibTorch/install/lib/libtorch.a(empty.cpp.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/user/Development/mobileTorch/ios-demo-app/HelloWorld/HelloWorld/Pods/LibTorch/install/lib/libtorch.a' for architecture arm64
clang: error: linker command failed with exit code 1


System: 2020 Macbook Air Apple M1 silicon


Steps taken:

  • Installed libtorch 1.7 with sudo gem install ffi and then pod install

  • Tried to build with various different iOS emulators

  • Installing the gems both with Rosetta and natively

I presume the issue lies somewhere in the apple silicon but I'm not sure what else to try.

hello, I have the same problem, did you find a solution, I use macbook pro M1 pro

Me too, I'm having the same problem. LibTorch is not installing as CocoaPods dependency with MacBook M1. Can someone who found an answer to this please write a reply? Thanks.

Strangely if I install 'LibTorch-Lite' with 'OpenCV' https://github.com/pytorch/ios-demo-app/tree/master/HelloWorld runs on simulator too.

platform :ios, '12.0'
target 'HelloWorld' do
    pod 'LibTorch-Lite'
    pod 'OpenCV'
end

Found an answer of not building on iPhone Simulator with M1 MacBook:

  1. For building App.

A. MyProject -> TARGETS -> MyProject -> Build Settings -> Excluded Architectures -> Add arm64

B. Pods -> PROJECT -> Pods -> Build Settings -> Excluded Architectures -> Add arm64

  1. For building CocoaPods library.

Add below in podspec.

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS' => 'arm64' }

s.user_target_xcconfig = { 'EXCLUDED_ARCHS' => 'arm64' }

Getting import CocoaPod error if I do below, still debugging

s.pod_target_xcconfig = { 'EXCLUDED_ARCHS' => 'arm64' } s.user_target_xcconfig = { 'EXCLUDED_ARCHS' => 'arm64' }

Try running on real iOS device instead of simulator

Xcode and LibTorch on Apple M1 Silicon
 
 
Q