Issues with building libtorch on linux

grmnptr: <p>Hi!<br>
So I am trying to build libtorch on my linux machine using cmake and the instructions here:</p><aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="noopener nofollow ugc">pytorch/pytorch/blob/master/docs/libtorch.rst</a></h4>


    <pre><code class="lang-rst">libtorch (C++-only)
===================

The core of pytorch does not depend on Python. A
CMake-based build system compiles the C++ source code into a shared
object, libtorch.so.

Building libtorch using Python
------------------------------

You can use a python script/module located in tools package to build libtorch
::
   cd &lt;pytorch_root&gt;

   # Make a new folder to build in to avoid polluting the source directories
   mkdir build_libtorch &amp;&amp; cd build_libtorch

   # You might need to export some required environment variables here.
   Normally setup.py sets good default env variables, but you'll have to do
   that manually.
</code></pre>


  This file has been truncated. <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="noopener nofollow ugc">show original</a>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>For this, first I create a conda environment, and install the packages highlighted here:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/pytorch/pytorch">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/pytorch/pytorch" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/5a302b21be2cec821b93d37f094c998121f92356d715c4fc4f04ba3876117868/pytorch/pytorch" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/pytorch/pytorch" target="_blank" rel="noopener nofollow ugc">GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with...</a></h3>

  <p>Tensors and Dynamic neural networks in Python with strong GPU acceleration - GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>I am trying to configure my build using the following command:</p>
<pre><code class="lang-auto">cmake -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Release -DPYTHON_EXECUTABLE:PATH=`which python3` -DCMAKE_INSTALL_PREFIX:PATH=/raid/projects/pytorch-install -DGLIBCXX_USE_CXX11_ABI=0 -DBUILD_PYTHON:BOOL=OFF ../pytorch
</code></pre>
<p>During the configuration step I see strange warnings ending that they are meant for developers only. I am not sure if that is normal or not, but the configure finishes without other issues. Then I move on an call:</p>
<pre><code class="lang-auto">cmake --build . -j 16 --target install
</code></pre>
<p>It compiles seemingly without an issue but I see warnings like:</p>
<pre><code class="lang-auto">[ 13%] Building CXX object third_party/ideep/mkl-dnn/src/cpu/CMakeFiles/dnnl_cpu.dir/nspc_batch_normalization.cpp.o

Skipping full_like because it is a factory method
Skipping from_file because it is a factory method
Skipping hann_window because it is a factory method
Skipping hamming_window because it is a factory method
Skipping kaiser_window because it is a factory method
Skipping index_copy Because of Arg: Dimname (Dimname)
Skipping kthvalue Because of Arg: Dimname (Dimname)
Skipping kthvalue Because of Arg: Dimname (Dimname)
Skipping fbgemm_linear_quantize_weight Because of Ret: double (double)
Skipping linspace because it is a factory method
Skipping logspace because it is a factory method
... more lines like that ...
... more lines like that ...
</code></pre>
<p>It seems it only affects the mkl-ddn part. I tried it on an HPC and my laptop, with PT 1.10 and 1.7 and I get the same issues. Following this, when I try to link libtorch with another code I get errors like this:</p>
<pre><code class="lang-auto">/data/miniconda3/envs/pytorch-conda39-build/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /raid/projects/pytorch-install/lib/libtorch_cpu.so: undefined reference to `MKL_Somatadd'
/data/miniconda3/envs/pytorch-conda39-build/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /raid/projects/pytorch-install/lib/libtorch_cpu.so: undefined reference to `MKL_Get_Version_String'
/data/miniconda3/envs/pytorch-conda39-build/bin/../lib/gcc/x86_64-conda-linux-gnu/9.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: /raid/projects/pytorch-install/lib/libtorch_cpu.so: undefined reference to `vsSqrt'
... more errors like that ...
... more errors like that ...
</code></pre>
<p>which is rather strange. I wonder if the two issues are related. Has anybody seen this behavior before?</p>