How to build libtorch to get the output of the offical libtorch release?

username: brainoom
cooked: <p>I am trying to build libtorch, to make it usable from a cmake project, to get a result like the offical build in here: download pytorch org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip<br>
is what I want to get, but I was unable to get it by following this exactly:</p>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="nofollow noopener">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
-----------------

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="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>I used pytorch 1.4.0 tag on ubuntu16.04, and followed the above instructions exactly. What I got in pytorch_build folder is another folder named build, and in it a mess of cmake build “residuals” like the “CMakeFiles” folder, together with the lib, bin and include folders, but without the “share” folder.</p>
<p>Did anyone has success following these instructions?</p>
<p>The discussion I’ve found, here:<br>
discuss pytorch org/t/building-libtorch-c-distribution-from-source/27519/2<br>
triggers this issue:</p>
<p><aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/issues/20271" target="_blank" rel="nofollow noopener">github.com/pytorch/pytorch</a>
  </header>
  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewbox="0 0 14 16" aria-hidden="true"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/issues/20271" target="_blank" rel="nofollow noopener">Official instructions for how to build libtorch don't have same structure as prebuilt binaries</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2019-05-08" data-time="13:02:51" data-timezone="UTC">01:02PM - 08 May 19 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2019-05-30" data-time="19:52:28" data-timezone="UTC">07:52PM - 30 May 19 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/ezyang" target="_blank" rel="nofollow noopener">
          <img alt="ezyang" src="https://avatars0.githubusercontent.com/u/13564?v=4" class="onebox-avatar-inline" width="20" height="20">
          ezyang
        </a>
      </div>
    </div>
  </div>
</div>

<div class="github-row">
  <p class="github-content">On Slack, Geoffrey Yu asked:
Are there instructions for building libtorch from source? I feel like I'm missing something since I've tried...</p>
</div>

<div class="labels">
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">high priority</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: binaries</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: build</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: cpp</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: docs</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">triaged</span>
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
which was closed with updated instructions, But I follow them and still do not get anything like the official build.</p>
<p>A similar question have been unanswered here: on question discuss pytorch org/t/how-to-build-libtorch-with-cmake/42723</p>
<p>Sorry for not including the full links, I’m a new user and discuss won’t let me include more than two links</p>
<p>Any ideas?<br>
Should this be an issue to be opened on github?</p>
<p>Thanks</p>

username: Hartbook
cooked: <p>Once everything has been compiled you can find include/ lib/ and share/ directories inside pytorch/torch/</p>

username: brainoom
cooked: <p>Thank for the answer! But how did It get there?! it’s a pretty messy build, when the build sprays files all over your source dir…</p>
<p>I imagine/hope this is not the way the official release is created.</p>