Compile a model with libtorch locally built from the source

username: sunggg
cooked: <p>Happy new year!</p>
<p>I built libtorch locally by following <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst#building-libtorch-using-python" rel="noopener nofollow ugc">this instruction</a>.<br>
However, I’m having trouble to use this to compile models.</p>
<p>I changed my <code>CMakeLists.txt</code> as follows:</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)

set(CMAKE_PREFIX_PATH "~/pytorch/build_libtorch/build")

find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
</code></pre>
<p>When running the <code>cmake</code>, I meet bunch of errors like following:</p>
<pre><code class="lang-auto">CMake Error at /home/spark/pytorch/build_libtorch/build/Caffe2Config.cmake:14 (include):
  include could not find requested file:

    /home/spark/pytorch/build_libtorch/build/public/utils.cmake
Call Stack (most recent call first):
  /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:6 (find_package)


CMake Error at /home/spark/pytorch/build_libtorch/build/Caffe2Config.cmake:17 (include):
  include could not find requested file:

    /home/spark/pytorch/build_libtorch/build/public/threads.cmake
Call Stack (most recent call first):
  /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:6 (find_package)


CMake Error at /home/spark/pytorch/build_libtorch/build/Caffe2Config.cmake:92 (include):
  include could not find requested file:

    /home/spark/pytorch/build_libtorch/build/public/cuda.cmake
Call Stack (most recent call first):
  /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:6 (find_package)


CMake Error at /home/spark/pytorch/build_libtorch/build/Caffe2Config.cmake:113 (include):
  include could not find requested file:

    /home/spark/pytorch/build_libtorch/build/public/mkl.cmake
Call Stack (most recent call first):
  /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:6 (find_package)


CMake Error at /home/spark/pytorch/build_libtorch/build/Caffe2Config.cmake:116 (include):
  include could not find requested file:

    /home/spark/pytorch/build_libtorch/build/public/mkldnn.cmake
Call Stack (most recent call first):
  /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:6 (find_package)


CMake Error at /home/spark/pytorch/build_libtorch/build/Caffe2Config.cmake:120 (include):
  include could not find requested file:

    /home/spark/pytorch/build_libtorch/build/Caffe2Targets.cmake
Call Stack (most recent call first):
  /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:6 (find_package)


CMake Error at /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:182 (set_target_properties):
  set_target_properties Can not find target to add properties to: torch
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)


CMake Error at /home/spark/pytorch/build_libtorch/build/TorchConfig.cmake:187 (set_property):
  set_property could not find TARGET torch.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)
</code></pre>
<p>I suspect the official release of libtorch does some kind of tricks that the build instruction does not provide.<br>
I would appreciate any help or advice.<br>
Thank you!</p>

username: sunggg
cooked: <p>Update: Tried <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst#building-libtorch-using-cmake" rel="noopener nofollow ugc">build with cmake</a> as well but still does not generate <code>public/</code> directory.</p>

username: oriongineer
cooked: <p>I am also having this issue, did you find a solution?</p>