Libtorch make linker error on M2 Mac

Following the exact steps in Installing C++ Distributions of PyTorch — PyTorch main documentation, I created the following file structure as indicated

when I run
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch …
cmake --build . --config Release

I get the following linker error

[ 50%] Building CXX object CMakeFiles/example-app.dir/example-app.cpp.o
[100%] Linking CXX executable example-app
ld: warning: directory not found for option ‘-L/lib/intel64’
ld: warning: directory not found for option ‘-L/lib/intel64_win’
ld: warning: directory not found for option ‘-L/lib/win-x64’
ld: unknown option: --no-as-needed
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


Collecting environment information…
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 14.0 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.
CMake version: version 3.27.3
Libc version: N/A

Python version: 3.9.6 (default, Aug 12 2023, 13:13:19) [Clang 15.0.0 (clang-1500.0.37.1) ] (64-bit runtime)
Python platform: macOS-14.1-arm64-arm-64bit
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

Apple M2 Pro

Versions of relevant libraries:
[pip3] numpy==1.19.0

In the instructions, try replacing the following:


With a mac specific distribution Start Locally | PyTorch

So for M2 chip it would be