title: cmake - linking static library pytorch cannot find its internal functions during build
body: <p>I'm trying to build a program using cmake. For several reasons, the program must be built using static libraries rather than dynamic libraries, and I need to use PyTorch so this is what I've done:</p>
  
  <ol>
  <li>Downloaded and installed PyTorch static library (I've found <code>libtorch.a</code> in the proper path, in <code>/home/me/pytorch/torch/lib</code>)</li>
  <li>Made <code>CMakeLists.txt</code> with the following contents:</li>
  </ol>
  
  <pre><code>cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
  project(example-app LANGUAGES CXX)
  find_package(Torch REQUIRED)
  add_executable(example-app example-app.cpp argparse/argparse.cpp)
  target_link_libraries(example-app "${TORCH_LIBRARIES}" -static -fopenmp)
  set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
  </code></pre>
  
  <p>FYI, <code>example-app.cpp</code> is the file with the main function, and <code>argparse/</code> is a directory with some source code for functions called in <code>example-app.cpp</code></p>
  
  <p>It works until <code>cmake -DCMAKE_PREFIX_PATH=/home/me/pytorch/torch ..</code>, but the following <code>build</code> incurs some errors, saying it could not find the reference to some functions, namely functions starting with <code>fbgemm::</code>. <code>fbgemm</code> is (as long as I know) some sort of GEMM library used in implementing PyTorch.</p>
  
  <p>It seems to me that while linking the static PyTorch library, its internal libraries like <code>fbgemm</code> stuff have not been linked properly, but I'm not an expert on <code>cmake</code> and honestly not entirely sure.</p>
  
  <p>Am I doing something wrong, or is there a workaround for this problem? Any help or push in the right direction would be greatly appreciated.</p>
  
  <p><strong>P.S.</strong></p>
  
  <ol>
  <li><p>The exact error has not been posted because it is way too long, but it consists of mostly <code>undefined reference to ~</code> errors. If looking at the error message might be helpful for some people, I'd be happy to edit the question and post it.</p></li>
  <li><p><code>build</code>ing and running the file works fine if I remove the parts that require the library's functions from the code <em>without</em> commenting out <code>#include &lt;torch/torch.h&gt;</code> from <code>example-app.cpp</code>.</p></li>
  </ol>