Compilation of Libtorch with wmake rather than cmake

username: arslansadiq
cooked: <p>Hi,<br>
I hope that you all are having a good day.</p>
<p>I am trying to use Libtorch library for my OpenFoam simulations. The problem here is that, the <a href="https://pytorch.org/tutorials/advanced/cpp_export.html" rel="noopener nofollow ugc">tutorial given on the pytorch website</a> does it via CMake. Now the problem is, OpenFoam uses its own compilation script <a href="https://cfd.direct/openfoam/user-guide/v6-compiling-applications/" rel="noopener nofollow ugc"><code>wmake</code></a> which is based on <code>make</code> for the compilation of its solvers.</p>
<p>In the tutorial linked above it says that:</p>
<blockquote>
<p>CMake is not a requirement for depending on LibTorch.</p>
</blockquote>
<p>Now that means I can somehow use <code>wmake</code> for it. Can anybody tell me the correct procedure to link all the shared objects files in in the <code>libtorch/lib</code> folder in my <code>Make/options</code> files. I tried doing it as it is explained in the wmake link which I have attached above but it doesn’t compile and it throws following problems:</p>
<pre><code class="lang-auto">Make/linux64GccDPInt32Opt/inferFoam.o: In function `torch::autograd::Variable::AutogradMeta::set_requires_grad(bool, c10::TensorImpl*)':
inferFoam.C:(.text._ZN5torch8autograd8Variable12AutogradMeta17set_requires_gradEbPN3c1010TensorImplE[_ZN5torch8autograd8Variable12AutogradMeta17set_requires_gradEbPN3c1010TensorImplE]+0x13c): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN5torch8autograd8Variable12AutogradMeta17set_requires_gradEbPN3c1010TensorImplE[_ZN5torch8autograd8Variable12AutogradMeta17set_requires_gradEbPN3c1010TensorImplE]+0x2a3): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o: In function `at::legacyTensorType(c10::TensorImpl const&amp;)':
inferFoam.C:(.text._ZN2at16legacyTensorTypeERKN3c1010TensorImplE[_ZN2at16legacyTensorTypeERKN3c1010TensorImplE]+0x626): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN2at16legacyTensorTypeERKN3c1010TensorImplE[_ZN2at16legacyTensorTypeERKN3c1010TensorImplE]+0x750): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o: In function `torch::OrderedDict&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::unique_ptr&lt;torch::jit::script::Method, std::default_delete&lt;torch::jit::script::Method&gt; &gt; &gt;::operator[](std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) const':
inferFoam.C:(.text._ZNK5torch11OrderedDictINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt10unique_ptrINS_3jit6script6MethodESt14default_deleteISA_EEEixERKS6_[_ZNK5torch11OrderedDictINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt10unique_ptrINS_3jit6script6MethodESt14default_deleteISA_EEEixERKS6_]+0x1c2): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o:inferFoam.C:(.text._ZN3c1013intrusive_ptrINS_20intrusive_ptr_targetENS_6detail34intrusive_target_default_null_typeIS1_EEE7reclaimEPS1_[_ZN3c1013intrusive_ptrINS_20intrusive_ptr_targetENS_6detail34intrusive_target_default_null_typeIS1_EEE7reclaimEPS1_]+0x120): more undefined references to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)' follow
Make/linux64GccDPInt32Opt/inferFoam.o: In function `torch::zeros(c10::ArrayRef&lt;long&gt;, c10::TensorOptions const&amp;)':
inferFoam.C:(.text._ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE[_ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE]+0x96): undefined reference to `c10::Symbol::fromQualString(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE[_ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE]+0x209): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE[_ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE]+0x8d8): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE[_ZN5torch5zerosEN3c108ArrayRefIlEERKNS0_13TensorOptionsE]+0x9f7): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o: In function `c10::raw::intrusive_ptr::incref(c10::intrusive_ptr_target*)':
inferFoam.C:(.text._ZN3c103raw13intrusive_ptr6increfEPNS_20intrusive_ptr_targetE[_ZN3c103raw13intrusive_ptr6increfEPNS_20intrusive_ptr_targetE]+0x147): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o: In function `void std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;::_M_realloc_insert&lt;c10::IValue const&amp;&gt;(__gnu_cxx::__normal_iterator&lt;c10::IValue*, std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt; &gt;, c10::IValue const&amp;)':
inferFoam.C:(.text._ZNSt6vectorIN3c106IValueESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT_[_ZNSt6vectorIN3c106IValueESaIS1_EE17_M_realloc_insertIJRKS1_EEEvN9__gnu_cxx17__normal_iteratorIPS1_S3_EEDpOT_]+0x412): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o:inferFoam.C:(.text._ZN3c1012unshapedTypeERKSt10shared_ptrINS_4TypeEE[_ZN3c1012unshapedTypeERKSt10shared_ptrINS_4TypeEE]+0x4a7): more undefined references to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)' follow
Make/linux64GccDPInt32Opt/inferFoam.o: In function `torch::jit::script::Method::defaultSchemaFor(torch::jit::script::Method const&amp;)':
inferFoam.C:(.text._ZN5torch3jit6script6Method16defaultSchemaForERKS2_[_ZN5torch3jit6script6Method16defaultSchemaForERKS2_]+0x174): undefined reference to `torch::jit::Value::uniqueNameBase[abi:cxx11]() const'
inferFoam.C:(.text._ZN5torch3jit6script6Method16defaultSchemaForERKS2_[_ZN5torch3jit6script6Method16defaultSchemaForERKS2_]+0x4fb): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN5torch3jit6script6Method16defaultSchemaForERKS2_[_ZN5torch3jit6script6Method16defaultSchemaForERKS2_]+0xa77): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN5torch3jit6script6Method16defaultSchemaForERKS2_[_ZN5torch3jit6script6Method16defaultSchemaForERKS2_]+0xdb5): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o: In function `torch::jit::script::Method::checkInputsAgainstSchema(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;&amp;)':
inferFoam.C:(.text._ZN5torch3jit6script6Method24checkInputsAgainstSchemaERSt6vectorIN3c106IValueESaIS5_EE[_ZN5torch3jit6script6Method24checkInputsAgainstSchemaERSt6vectorIN3c106IValueESaIS5_EE]+0x407): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text._ZN5torch3jit6script6Method24checkInputsAgainstSchemaERSt6vectorIN3c106IValueESaIS5_EE[_ZN5torch3jit6script6Method24checkInputsAgainstSchemaERSt6vectorIN3c106IValueESaIS5_EE]+0x909): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o:inferFoam.C:(.text._ZN5torch3jit6script6Method24checkInputsAgainstSchemaERSt6vectorIN3c106IValueESaIS5_EE[_ZN5torch3jit6script6Method24checkInputsAgainstSchemaERSt6vectorIN3c106IValueESaIS5_EE]+0xb47): more undefined references to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)' follow
Make/linux64GccDPInt32Opt/inferFoam.o: In function `main':
inferFoam.C:(.text.startup+0x114a): undefined reference to `torch::jit::load(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, c10::optional&lt;c10::Device&gt;)'
inferFoam.C:(.text.startup+0x1a3d): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text.startup+0x4ee6): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text.startup+0x5106): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text.startup+0x530b): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
inferFoam.C:(.text.startup+0x5bbb): undefined reference to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
Make/linux64GccDPInt32Opt/inferFoam.o:inferFoam.C:(.text.startup+0x5cad): more undefined references to `c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)' follow
collect2: error: ld returned 1 exit status

</code></pre>