Libtorch make linker error on M2 Mac

sjoptra: <p>Following the exact steps in <a href="https://pytorch.org/cppdocs/installing.html" class="inline-onebox" rel="noopener nofollow ugc">Installing C++ Distributions of PyTorch — PyTorch main documentation</a>, I created the following file structure as indicated<br>
example-app/<br>
CMakeLists.txt<br>
example-app.cpp</p>
<p>when I run<br>
mkdir build<br>
cd build<br>
cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch …<br>
cmake --build . --config Release</p>
<p>I get the following linker error</p>
<p>[ 50%] Building CXX object CMakeFiles/example-app.dir/example-app.cpp.o<br>
[100%] Linking CXX executable example-app<br>
ld: warning: directory not found for option ‘-L/lib/intel64’<br>
ld: warning: directory not found for option ‘-L/lib/intel64_win’<br>
ld: warning: directory not found for option ‘-L/lib/win-x64’<br>
ld: unknown option: --no-as-needed<br>
clang: error: linker command failed with exit code 1 (use -v to see invocation)<br>
make[2]: *** [example-app] Error 1<br>
make[1]: *** [CMakeFiles/example-app.dir/all] Error 2<br>
make: *** [all] Error 2</p>
<h3><a name="versions-1" class="anchor" href="#versions-1"></a>Versions</h3>
<p>Collecting environment information…<br>
PyTorch version: N/A<br>
Is debug build: N/A<br>
CUDA used to build PyTorch: N/A<br>
ROCM used to build PyTorch: N/A</p>
<p>OS: macOS 14.0 (arm64)<br>
GCC version: Could not collect<br>
Clang version: 15.0.0 (clang-1500.0.28.1.1)<br>
CMake version: version 3.27.3<br>
Libc version: N/A</p>
<p>Python version: 3.9.6 (default, Aug 12 2023, 13:13:19) [Clang 15.0.0 (clang-1500.0.37.1) ] (64-bit runtime)<br>
Python platform: macOS-14.1-arm64-arm-64bit<br>
Is CUDA available: N/A<br>
CUDA runtime version: Could not collect<br>
CUDA_MODULE_LOADING set to: N/A<br>
GPU models and configuration: Could not collect<br>
Nvidia driver version: Could not collect<br>
cuDNN version: Could not collect<br>
HIP runtime version: N/A<br>
MIOpen runtime version: N/A<br>
Is XNNPACK available: N/A</p>
<p>CPU:<br>
Apple M2 Pro</p>
<p>Versions of relevant libraries:<br>
[pip3] numpy==1.19.0</p>

ekam123: <p>In the instructions, try replacing the following:</p>
<pre><code class="lang-auto">wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
unzip libtorch-shared-with-deps-latest.zip
</code></pre>
<p>With a mac specific distribution <a href="https://pytorch.org/get-started/locally/" class="inline-onebox" rel="noopener nofollow ugc">Start Locally | PyTorch</a></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/b/cb5fb7d9cce2127dbfc861fb3da5a8c774b5703d.png" data-download-href="https://discuss.pytorch.org/uploads/default/cb5fb7d9cce2127dbfc861fb3da5a8c774b5703d" title="Screen Shot 2024-03-24 at 12.29.42 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/b/cb5fb7d9cce2127dbfc861fb3da5a8c774b5703d_2_690x313.png" alt="Screen Shot 2024-03-24 at 12.29.42 PM" data-base62-sha1="t1806DVCFnjEpC69pR2kecxWScZ" width="690" height="313" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/b/cb5fb7d9cce2127dbfc861fb3da5a8c774b5703d_2_690x313.png, https://discuss.pytorch.org/uploads/default/original/3X/c/b/cb5fb7d9cce2127dbfc861fb3da5a8c774b5703d.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/c/b/cb5fb7d9cce2127dbfc861fb3da5a8c774b5703d.png 2x" data-dominant-color="F6D8D5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screen Shot 2024-03-24 at 12.29.42 PM</span><span class="informations">867×394 41.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>So for M2 chip it would be <a href="https://download.pytorch.org/libtorch/cpu/libtorch-macos-arm64-2.2.1.zip" rel="noopener nofollow ugc">https://download.pytorch.org/libtorch/cpu/libtorch-macos-arm64-2.2.1.zip</a></p>