Build A Pytorch Wrapper - Error c10::IValue::toDouble() const [Similar Errors]

krrishabh: <p><strong>Configuration :</strong></p>
<pre><code class="lang-auto">-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/local/miniconda3/bin/python (found version "3.7.3")
-- Running gen_cmake_skeleton.py
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found BLAS: /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/OpenBLAS/libopenblas.so
-- A library with LAPACK API found.
-- Found CUDA: /usr/local/cuda (found version "10.1")
-- Found NvToolExt: /usr/local/cuda/include
-- Found CUB: /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cub
-- Found CUDA: /usr/local/cuda (found version "10.1")
-- Caffe2: CUDA detected: 10.1
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 10.1
-- Found CUDNN: /usr/lib/x86_64-linux-gnu/libcudnn.so
-- Found cuDNN: v7.6.1 (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libcudnn.so)
-- Autodetected CUDA architecture(s): 6.1 6.1 6.1 6.1
-- Added CUDA NVCC flags for: -gencode;arch=compute_61,code=sm_61
-- Found Torch: /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch.so
</code></pre>
<p><strong>Error Message</strong></p>
<pre><code class="lang-auto">lattice-lmrescore-py-rnnlm.cc:(.text._ZN3c1019UndefinedTensorImpl9singletonEv[_ZN3c1019UndefinedTensorImpl9singletonEv]+0x7): undefined reference to `c10::UndefinedTensorImpl::_singleton'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toDouble() const':
lattice-lmrescore-py-rnnlm.cc:(.text._ZNK3c106IValue8toDoubleEv[_ZNK3c106IValue8toDoubleEv]+0xa0): undefined reference to `c10::Error::Error(c10::SourceLocation, std::string const&amp;)'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toInt() const':
lattice-lmrescore-py-rnnlm.cc:(.text._ZNK3c106IValue5toIntEv[_ZNK3c106IValue5toIntEv]+0xa0): undefined reference to `c10::Error::Error(c10::SourceLocation, std::string const&amp;)'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toTensor() const &amp;':
...
...
_ZTIN5torch8autograd12AutogradMetaE]+0x10): undefined reference to `typeinfo for c10::AutogradMetaInterface'
collect2: error: ld returned 1 exit status
src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/build.make:122: recipe for target 'src/pyrnnlmbin/lattice-lmrescore-py-rnnlm' failed
</code></pre>
<p><strong>kaldi -&gt; CMakLists.txt</strong><br>
Even I added <strong>add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0</strong>) also</p>
<p>all the pyrnnlm-&gt;CMakeLists.txt and pyrnnlmbin-&gt;CMakeLists.txt</p>
<p><strong>pyrnnlm -&gt; CMakeLists.txt</strong></p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(PUBLIC_HEADERS
    pytorch-rnnlm.h
)

add_library(kaldi-pyrnnlm
    pytorch-rnnlm.cc
)

target_include_directories(kaldi-pyrnnlm PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/caffe2&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/ATen/core&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/c10&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib&gt;)

#link_directories(/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch)

#target_include_directories(kaldi-pyrnnlm PUBLIC 
#    ${PYTORCH_DIR}
#    ${PYTORCH_DIR}/bin
#    ${PYTORCH_DIR}/include
#    ${PYTORCH_DIR}/share
#
#)

set(CMAKE_CXX_STANDARD 14)

target_include_directories(kaldi-pyrnnlm PUBLIC 
     $&lt;BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..&gt;
     $&lt;INSTALL_INTERFACE:include/kaldi&gt;
     #/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch/include
   #/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include
)

target_link_libraries(kaldi-pyrnnlm PUBLIC
    kaldi-lm
    kaldi-util
    kaldi-matrix
    kaldi-base
    -lz
    -ldl
    -fPIC
    -L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch
    -L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib
    -L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64

)

find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

#target_link_libraries(kaldi-pyrnnlm "${TORCH_LIBRARIES}")
#set_property(TARGET kaldi-pyrnnlm PROPERTY CXX_STANDARD 14)

install(TARGETS kaldi-pyrnnlm
    EXPORT kaldi-targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES ${PUBLIC_HEADERS} DESTINATION include/kaldi/pyrnnlm)


</code></pre>
<p><strong>pyrnnlmbin -&gt; CMakeLists.txt (Calling the above CMakeLists.txt)</strong></p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
#find_package(Torch REQUIRED)
#find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

set(CMAKE_CXX_STANDARD 14)

add_kaldi_executable(NAME lattice-lmrescore-py-rnnlm SOURCES lattice-lmrescore-py-rnnlm.cc DEPENDS kaldi-pyrnnlm kaldi-lat)

#target_link_libraries(lattice-lmrescore-py-rnnlm "${PYTORCH_DIR}")
#set_property(TARGET lattice-lmrescore-py-rnnlm PROPERTY CXX_STANDARD 14)

</code></pre>
<p>Tried all similar issues solution mention in the forum.</p>

glaringlee: <p><a class="mention" href="/u/krrishabh">@krrishabh</a><br>
The error you got is due to .so missing in my opinion.<br>
Can you make a change here and try?<br>
Put target_link_libraries under find_package, add linking library in target_link_libraries only, like this:</p>
<p>find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)<br>
target_link_libraries(kaldi-pyrnnlm PUBLIC<br>
kaldi-lm<br>
kaldi-util<br>
kaldi-matrix<br>
kaldi-base<br>
${TORCH_LIBRARIES}<br>
)</p>
<p>And then add -lz, -ldl, -fPIC to target_compile_options, they are not linking libraries.</p>

krrishabh: <p>When I kept as you said</p>
<pre><code class="lang-auto">
target_link_libraries(kaldi-pyrnnlm PUBLIC
kaldi-lm
kaldi-util
kaldi-matrix
kaldi-base
${TORCH_LIBRARIES}
)
</code></pre>
<p><strong>${TORCH_LIBRARIES}</strong> in the target_link_libraries gives error as</p>
<pre><code class="lang-auto">CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cpu,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES&gt;

  Target "torch_cpu" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES&gt;

  Target "torch_cpu" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cuda,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES&gt;

  Target "torch_cuda" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cuda,INTERFACE_INCLUDE_DIRECTORIES&gt;

  Target "torch_cuda" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES&gt;

  Target "torch" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES&gt;

  Target "torch" not found.
</code></pre>
<p>So, I comment <strong>${TORCH_LIBRARIES}</strong><br>
If I used…</p>
<pre><code class="lang-auto">target_include_directories(kaldi-pyrnnlm PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/caffe2&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/ATen/core&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/c10/util&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib&gt;
PUBLIC $&lt;BUILD_INTERFACE:/usr/local/lib/python3.6/dist-packages/torch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64/stubs&gt;
)

target_link_libraries(kaldi-pyrnnlm PUBLIC
    kaldi-lm
    kaldi-util
    kaldi-matrix
    kaldi-base
    libc10.so
    libc10_cuda.so
    #-lz
    #-ldl
    #-fPIC
    #${TORCH_LIBRARIES}
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64

)

</code></pre>
<p>Then I got only 2 error as</p>
<pre><code class="lang-auto">/usr/bin/ld: cannot find -lc10
/usr/bin/ld: cannot find -lc10_cuda
collect2: error: ld returned 1 exit status
src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/build.make:122: recipe for target 'src/pyrnnlmbin/lattice-lmrescore-py-rnnlm' failed
make[2]: *** [src/pyrnnlmbin/lattice-lmrescore-py-rnnlm] Error 1
CMakeFiles/Makefile2:7492: recipe for target 'src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/all' failed
make[1]: *** [src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/all] Error 2
</code></pre>
<p>Repository : <a href="https://github.com/cyfer0618/kaldi-pytorch-rnnlm.git" rel="nofollow noopener">https://github.com/cyfer0618/kaldi-pytorch-rnnlm.git</a></p>

glaringlee: <p><a class="mention" href="/u/krrishabh">@krrishabh</a><br>
I don’t think you should comment  ${TORCH_LIBRARIES}.<br>
The reason that torch_cpu, torch_cuda, torch etc. can not be found is that you did not specify there location. You give the PATHS in find_package, so cmake can find the torch package, but target_link_libraries does not know the libtorch path there.</p>
<p>Can you try setup CMAKE_PREFIX_PATH? append libtorch’s path to it.<br>
Here is a libtorch compile instruction,<br>
‘<a href="https://pytorch.org/cppdocs/installing.html" rel="nofollow noopener">https://pytorch.org/cppdocs/installing.html</a>’<br>
you can specify CMAKE_PREFIX_PATH in cmake commend line as well.</p>

krrishabh: <p>Sir I tried both…<br>
CMakeLists.txt File</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(PUBLIC_HEADERS
    pytorch-rnnlm.h
)

add_library(kaldi-pyrnnlm
    pytorch-rnnlm.cc
)

#set(D_GLIBCXX_USE_CXX11_ABI,"0")
list(APPEND CMAKE_PREFIX_PATH "/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch")


target_include_directories(kaldi-pyrnnlm PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/caffe2&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/ATen/core&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/c10/util&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/lib/python3.6/dist-packages/torch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64/stubs&gt;
)

#link_directories(/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch)

#target_include_directories(kaldi-pyrnnlm PUBLIC 
#    ${PYTORCH_DIR}
#    ${PYTORCH_DIR}/bin
#    ${PYTORCH_DIR}/include
#    ${PYTORCH_DIR}/share
#
#)

#set(CMAKE_CXX_STANDARD 14)

find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

target_include_directories(kaldi-pyrnnlm PUBLIC 
     $&lt;BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..&gt;
     $&lt;INSTALL_INTERFACE:include/kaldi&gt;
     #/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch/include
     #/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include
)

target_compile_options(kaldi-pyrnnlm PUBLIC 
    -lz
    -ldl
    -fPIC
)

target_link_libraries(kaldi-pyrnnlm PUBLIC
    kaldi-lm
    kaldi-util
    kaldi-matrix
    kaldi-base
    #libc10.so
    #libc10_cuda.so
    #-lz
    #-ldl
    #-fPIC
    #${TORCH_LIBRARIES}
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10.so
    /usr/local/cuda/lib64/libnvrtc.so
    /usr/local/cuda/lib64/stubs/libcuda.so;
    /usr/local/cuda/lib64/libnvToolsExt.so
    /usr/local/cuda/lib64/libcudart.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10_cuda.so
    #/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cpu.so
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64/studs/
)



#find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

MESSAGE("TORCH LIBS ${TORCH_LIBRARIES}")

#target_link_libraries(kaldi-pyrnnlm "${TORCH_LIBRARIES}")
#set_property(TARGET kaldi-pyrnnlm PROPERTY CXX_STANDARD 14)

install(TARGETS kaldi-pyrnnlm
    EXPORT kaldi-targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES ${PUBLIC_HEADERS} DESTINATION include/kaldi/pyrnnlm)

</code></pre>
<p>First</p>
<pre><code class="lang-auto">list(APPEND CMAKE_PREFIX_PATH "/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch")
</code></pre>
<p>Uncomment ${TORCH_LIBRARIES} but got the same error</p>
<pre><code class="lang-auto">CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cpu,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES&gt;

  Target "torch_cpu" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES&gt;

  Target "torch_cpu" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cuda,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES&gt;

  Target "torch_cuda" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch_cuda,INTERFACE_INCLUDE_DIRECTORIES&gt;

  Target "torch_cuda" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES&gt;

  Target "torch" not found.


CMake Error:
  Error evaluating generator expression:

    $&lt;TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES&gt;

  Target "torch" not found.
</code></pre>
<p>So, I went for adding individual library in target_link_libraries</p>
<pre><code class="lang-auto">    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10.so
    /usr/local/cuda/lib64/libnvrtc.so
    /usr/local/cuda/lib64/stubs/libcuda.so;
    /usr/local/cuda/lib64/libnvToolsExt.so
    /usr/local/cuda/lib64/libcudart.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10_cuda.so
</code></pre>
<p>And comment ${TORCH_LIBRARIES} but got the error</p>
<pre><code class="lang-auto">/usr/bin/ld: ../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): undefined reference to symbol '_ZN3c107IntType3getEv'
//home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cpu.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/build.make:128: recipe for target 'src/pyrnnlmbin/lattice-lmrescore-py-rnnlm' failed
</code></pre>
<p>And when I add this also in the target_link_libraries</p>
<pre><code class="lang-auto">/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cpu.so
</code></pre>
<p><strong>Got the main errors</strong></p>
<pre><code class="lang-auto">lattice-lmrescore-py-rnnlm.cc:(.text._ZN3c1019UndefinedTensorImpl9singletonEv[_ZN3c1019UndefinedTensorImpl9singletonEv]+0x7): undefined reference to `c10::UndefinedTensorImpl::_singleton'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toDouble() const':
lattice-lmrescore-py-rnnlm.cc:(.text._ZNK3c106IValue8toDoubleEv[_ZNK3c106IValue8toDoubleEv]+0xa0): undefined reference to `c10::Error::Error(c10::SourceLocation, std::string const&amp;)'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toInt() const':
lattice-lmrescore-py-rnnlm.cc:(.text._ZNK3c106IValue5toIntEv[_ZNK3c106IValue5toIntEv]+0xa0): undefined reference to `c10::Error::Error(c10::SourceLocation, std::string const&amp;)'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toTensor() const &amp;':
...
...
_ZTIN5torch8autograd12AutogradMetaE]+0x10): undefined reference to `typeinfo for c10::AutogradMetaInterface'
collect2: error: ld returned 1 exit status
src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/build.make:122: recipe for target 'src/pyrnnlmbin/lattice-lmrescore-py-rnnlm' failed
</code></pre>
<p>Repository : <a href="https://github.com/cyfer0618/kaldi-pytorch-rnnlm/blob/master/kaldi/src/pyrnnlm/CMakeLists.txt" rel="nofollow noopener">https://github.com/cyfer0618/kaldi-pytorch-rnnlm/blob/master/kaldi/src/pyrnnlm/CMakeLists.txt</a></p>

glaringlee: <p>Let’s break this into several steps.</p>
<ol>
<li>‘<a href="https://pytorch.org/cppdocs/installing.html%E2%80%99" rel="nofollow noopener">https://pytorch.org/cppdocs/installing.html’</a> follow this to build libtorch with simple example. Make sure it works.</li>
<li>Make sure your code compiled successfully before adding libtorch.</li>
<li>Now, start to do cross build, merge libtorch’s cmake file with your cmake file.</li>
</ol>
<p>For this, I think probably you need a cmake tutorial. It would be very hard for me figure out each symbol’s correct location in your makefile.</p>
<p>From your error log:<br>
a. I am not sure why setting up CMAKE_PREFIX_PATH doesn’t work. Can you try set it up in command line?<br>
b. I double checked -lz, -ldl, -fPIC, -lz and -ldl is libraries, and -fIPC is compile options. So you can put -lz and -ldl back to target_link_libraries and -fIPC should be compile options, you can try add_compile_opitions as well.<br>
c. You comment the “{TORCH_LIBRARIES}”, and add absolute path.<br>
Can you add libtorch_cpu.so, libtorch_gpu.so, libtorch_python.so as well. Please verify the libs here libtorch/lib, I think we don’t have libc10_cuda.so, but it is in your CMakeList.txt</p>

krrishabh: <p>Sir, I try the first three points. I did make a small example which was working fine with the same way I wrote this code. When I run the code <strong>pyrnnlm/CMakeLists.txt</strong> (with kaldi and without Kaldi) independently then it works fine. The <strong>pyrnnlmbin/CMakeLists.txt</strong> is calling <strong>pyrnnlm/CMakeLists.txt</strong> along with some kaldi CMakeLists.txt then there is an error.</p>
<p><strong>a.</strong> I tried CMAKE_PREFIX_PATH but when the <code>pyrnnlmbin/CMakeLists.txt</code> is calling <code>pyrnnlm/CMakeLists.txt</code> then it is not working which is why I have to add each and every library separately.<br>
<strong>b.</strong> I did this now. But then also I am getting the error.<br>
<strong>c.</strong> you have <strong>libc10_cuda.so</strong> but u don’t have <strong>libtorch_gpu.so</strong> . I have added all the library which u have mentioned above. But getting the same error as before.  I did all three points <strong>a, b and c</strong> points together.</p>
<p><strong>Error</strong></p>
<pre><code class="lang-auto">CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toDouble() const':
lattice-lmrescore-py-rnnlm.cc:(.text._ZNK3c106IValue8toDoubleEv[_ZNK3c106IValue8toDoubleEv]+0xa0): 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;)'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toInt() const':
lattice-lmrescore-py-rnnlm.cc:(.text._ZNK3c106IValue5toIntEv[_ZNK3c106IValue5toIntEv]+0xa0): 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;)'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::IValue::toTensor() const &amp;':
lattice-lmrescore-py-rnnlm.cc:(.text._ZNKR3c106IValue8toTensorEv[_ZNKR3c106IValue8toTensorEv]+0xeb): 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;)'
CMakeFiles/lattice-lmrescore-py-rnnlm.dir/lattice-lmrescore-py-rnnlm.cc.o: In function `c10::intrusive_ptr&lt;c10::TensorImpl, c10::UndefinedTensorImpl&gt;::retain_()':
lattice-lmrescore-py-rnnlm.cc:(.text._ZN3c1013intrusive_ptrINS_10TensorImplENS_19UndefinedTensorImplEE7retain_Ev[_ZN3c1013intrusive_ptrINS_10TensorImplENS_19UndefinedTensorImplEE7retain_Ev]+0xe1): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `c10::scalarTypeToTypeMeta(c10::ScalarType)':
pytorch-rnnlm.cc:(.text+0x307): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o):pytorch-rnnlm.cc:(.text+0xa04): 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
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `kaldi::py_rnnlm::KaldiPyRnnlmWrapper::ReadPyModel(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, int)':
pytorch-rnnlm.cc:(.text+0x1319): 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;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;&amp;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `kaldi::py_rnnlm::KaldiPyRnnlmWrapper::AcquireInitialTensors()':
pytorch-rnnlm.cc:(.text+0x210f): undefined reference to `torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;)'
pytorch-rnnlm.cc:(.text+0x245d): undefined reference to `torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `kaldi::py_rnnlm::KaldiPyRnnlmWrapper::GetLogProb(int, int, at::Tensor const&amp;, at::Tensor const&amp;, at::Tensor*, at::Tensor*)':
pytorch-rnnlm.cc:(.text+0x2a79): undefined reference to `torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;)'
pytorch-rnnlm.cc:(.text+0x2cba): undefined reference to `torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;)'
pytorch-rnnlm.cc:(.text+0x2f2c): undefined reference to `torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o):pytorch-rnnlm.cc:(.text+0x319e): more undefined references to `torch::jit::Method::operator()(std::vector&lt;c10::IValue, std::allocator&lt;c10::IValue&gt; &gt;, std::unordered_map&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, c10::IValue, std::hash&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::equal_to&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;std::pair&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const, c10::IValue&gt; &gt; &gt; const&amp;)' follow
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `c10::Device::validate()':
pytorch-rnnlm.cc:(.text._ZN3c106Device8validateEv[_ZN3c106Device8validateEv]+0x10f): 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;)'
pytorch-rnnlm.cc:(.text._ZN3c106Device8validateEv[_ZN3c106Device8validateEv]+0x25c): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `c10::intrusive_ptr_target::~intrusive_ptr_target()':
pytorch-rnnlm.cc:(.text._ZN3c1020intrusive_ptr_targetD2Ev[_ZN3c1020intrusive_ptr_targetD5Ev]+0xf8): 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;)'
pytorch-rnnlm.cc:(.text._ZN3c1020intrusive_ptr_targetD2Ev[_ZN3c1020intrusive_ptr_targetD5Ev]+0x1f5): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `c10::IValue::toTensor() &amp;&amp;':
pytorch-rnnlm.cc:(.text._ZNO3c106IValue8toTensorEv[_ZNO3c106IValue8toTensorEv]+0xeb): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o):pytorch-rnnlm.cc:(.text._ZNKR3c106IValue9toIntListEv[_ZNKR3c106IValue9toIntListEv]+0xeb): 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
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `torch::jit::Object::get_method(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) const':
pytorch-rnnlm.cc:(.text._ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x4e): undefined reference to `torch::jit::Object::find_method(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) const'
pytorch-rnnlm.cc:(.text._ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZNK5torch3jit6Object10get_methodERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x181): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `c10::intrusive_ptr&lt;c10::ivalue::Object, c10::detail::intrusive_target_default_null_type&lt;c10::ivalue::Object&gt; &gt;::retain_()':
pytorch-rnnlm.cc:(.text._ZN3c1013intrusive_ptrINS_6ivalue6ObjectENS_6detail34intrusive_target_default_null_typeIS2_EEE7retain_Ev[_ZN3c1013intrusive_ptrINS_6ivalue6ObjectENS_6detail34intrusive_target_default_null_typeIS2_EEE7retain_Ev]+0xe1): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `c10::intrusive_ptr&lt;c10::detail::ListImpl, c10::detail::intrusive_target_default_null_type&lt;c10::detail::ListImpl&gt; &gt;::retain_()':
pytorch-rnnlm.cc:(.text._ZN3c1013intrusive_ptrINS_6detail8ListImplENS1_34intrusive_target_default_null_typeIS2_EEE7retain_Ev[_ZN3c1013intrusive_ptrINS_6detail8ListImplENS1_34intrusive_target_default_null_typeIS2_EEE7retain_Ev]+0xe1): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `at::Tensor&amp; c10::KernelFunction::callUnboxed&lt;at::Tensor&amp;, at::Tensor&amp;, c10::Scalar&gt;(c10::OperatorHandle const&amp;, at::Tensor&amp;, c10::Scalar) const':
pytorch-rnnlm.cc:(.text._ZNK3c1014KernelFunction11callUnboxedIRN2at6TensorEJS4_NS_6ScalarEEEET_RKNS_14OperatorHandleEDpT0_[_ZNK3c1014KernelFunction11callUnboxedIRN2at6TensorEJS4_NS_6ScalarEEEET_RKNS_14OperatorHandleEDpT0_]+0x13a): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o): In function `at::Tensor c10::KernelFunction::callUnboxed&lt;at::Tensor, at::Tensor const&amp;, long, long&gt;(c10::OperatorHandle const&amp;, at::Tensor const&amp;, long, long) const':
pytorch-rnnlm.cc:(.text._ZNK3c1014KernelFunction11callUnboxedIN2at6TensorEJRKS3_llEEET_RKNS_14OperatorHandleEDpT0_[_ZNK3c1014KernelFunction11callUnboxedIN2at6TensorEJRKS3_llEEET_RKNS_14OperatorHandleEDpT0_]+0x16f): 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;)'
../pyrnnlm/libkaldi-pyrnnlm.a(pytorch-rnnlm.cc.o):pytorch-rnnlm.cc:(.text._ZNK3c1014KernelFunction11callUnboxedIN2at6TensorEJRKS3_RKNS_13TensorOptionsEbbNS_8optionalINS_12MemoryFormatEEEEEET_RKNS_14OperatorHandleEDpT0_[_ZNK3c1014KernelFunction11callUnboxedIN2at6TensorEJRKS3_RKNS_13TensorOptionsEbbNS_8optionalINS_12MemoryFormatEEEEEET_RKNS_14OperatorHandleEDpT0_]+0x1db): 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
src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/build.make:131: recipe for target 'src/pyrnnlmbin/lattice-lmrescore-py-rnnlm' failed
make[2]: *** [src/pyrnnlmbin/lattice-lmrescore-py-rnnlm] Error 1
CMakeFiles/Makefile2:7492: recipe for target 'src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/all' failed
make[1]: *** [src/pyrnnlmbin/CMakeFiles/lattice-lmrescore-py-rnnlm.dir/all] Error 2
</code></pre>
<p><strong>pyrnnlm/CMakeLists.txt</strong></p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(PUBLIC_HEADERS
    pytorch-rnnlm.h
)

add_library(kaldi-pyrnnlm
    pytorch-rnnlm.cc
)

#set(D_GLIBCXX_USE_CXX11_ABI,"0")
#list(APPEND CMAKE_PREFIX_PATH "/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch")


target_include_directories(kaldi-pyrnnlm PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/caffe2&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/ATen/core&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/c10/util&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/lib/python3.6/dist-packages/torch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64/stubs&gt;
)

#link_directories(/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch)

#target_include_directories(kaldi-pyrnnlm PUBLIC 
#    ${PYTORCH_DIR}
#    ${PYTORCH_DIR}/bin
#    ${PYTORCH_DIR}/include
#    ${PYTORCH_DIR}/share
#
#)

#set(CMAKE_CXX_STANDARD 14)

find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

target_include_directories(kaldi-pyrnnlm PUBLIC 
     $&lt;BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..&gt;
     $&lt;INSTALL_INTERFACE:include/kaldi&gt;
     #/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch/include
     #/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include
)

target_compile_options(kaldi-pyrnnlm PUBLIC 
    #-lz
    #-ldl
    -fPIC
)

target_link_libraries(kaldi-pyrnnlm PUBLIC
    kaldi-lm
    kaldi-util
    kaldi-matrix
    kaldi-base
    #libc10.so
    #libc10_cuda.so
    -lz
    -ldl
    #-fPIC
    #${TORCH_LIBRARIES}
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10.so
    /usr/local/cuda/lib64/libnvrtc.so
    /usr/local/cuda/lib64/stubs/libcuda.so;
    /usr/local/cuda/lib64/libnvToolsExt.so
    /usr/local/cuda/lib64/libcudart.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10_cuda.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cpu.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_python.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cuda.so
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64/studs/
)



#find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

MESSAGE("TORCH LIBS ${TORCH_LIBRARIES}")

#target_link_libraries(kaldi-pyrnnlm "${TORCH_LIBRARIES}")
#set_property(TARGET kaldi-pyrnnlm PROPERTY CXX_STANDARD 14)

install(TARGETS kaldi-pyrnnlm
    EXPORT kaldi-targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES ${PUBLIC_HEADERS} DESTINATION include/kaldi/pyrnnlm)

</code></pre>
<p><strong>pyrnnlmbin/CMakeLists.txt</strong></p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
#find_package(Torch REQUIRED)
#find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

set(CMAKE_CXX_STANDARD 14)

add_kaldi_executable(NAME lattice-lmrescore-py-rnnlm SOURCES lattice-lmrescore-py-rnnlm.cc DEPENDS kaldi-pyrnnlm kaldi-lat)

#target_link_libraries(lattice-lmrescore-py-rnnlm "${PYTORCH_DIR}")
#set_property(TARGET lattice-lmrescore-py-rnnlm PROPERTY CXX_STANDARD 14)

</code></pre>
<p>When <code>pyrnnlm/CMakeLists.txt</code> is compiled along with <strong>kaldi</strong> than there is no error and when the <code>pyrnnlmbin/CMakeLists.txt</code> is calling <code>pyrnnlm/CMakeLists.txt</code> than there is an error.</p>

glaringlee: <p><a class="mention" href="/u/krrishabh">@krrishabh</a></p>
<p>Ah. I see, you downloaded libtorch with cuda version, that’s why you have libc10_cuda.so. Yes, I typed libtorch_gpu.so, that’s a typo, what I meant is libtorch_cuda.so.</p>
<p>I think you should focus on getting cmake work with find_package() instead of adding .so by yourself, the reason is that pytorch is changing very fast, symbols might changed their .so file (where they are built in). So if you add .so by yourself, it might not work after a while.</p>
<p>for eg. in your error, ‘torch::jit::Object::find_method’ is in libpytorch_jni.so, so you have to add libpytorch_jni.so as well, but it might be built into another .so later, (we might split so files if they are too big). Based on your error msg,  you need to find each missing symbol in those .so files and add the .so into your CMakeList.txt.</p>
<p>If step 1 works for you (you can build a libtorch program following the instruction), please verify that both libtorch and your program using the same ABI setup and same compiler (gnu compatible), if so, I think this issue it going to be how to write a correct cmake file. I can not help much on writing cmake file for your program, that’s why I suggested in previous message that you should find a cmake tutorial (and plus google search for sure), and learn the related topic, eg. how to make PATH flags works in chaining call. The order of libraries sometimes matters as well.</p>
<p>==============================================================================<br>
If you do want to keep trying adding .so by yourself, you can try adding more .so files from libtorch/lib, at least that libpytorch_jni.so is one you needed as well, you might need more.</p>
<p>And by the way, I saw you have pytorch-rnnlm.cc, and lattice-lmrescore-py-rnnlm.cc, try to simplify those files by comments some of lines (or even all lines except <span class="hashtag">#inclue</span>) in those files, so you can narrow down the errors and solve them one by one.  But again, finding a cmake tutorial is more useful I think.</p>

krrishabh: <p>Thank you Sir and I will work on these points.</p>

krrishabh: <p>Sir, I added all the .so file in the CMakeLists.txt . But got the same error.</p>

krrishabh: <p>Sir, I have solved that…</p>

glaringlee: <p><a class="mention" href="/u/krrishabh">@krrishabh</a><br>
Glad you solved that. Do you mind sending me a copy of your working makefile?<br>
I am also curious on where was the problem.</p>

krrishabh: <p>Sir, My all three CMakeLists.txt is present in this repository : <a href="https://github.com/cyfer0618/kaldi-pytorch-rnnlm" rel="nofollow noopener">https://github.com/cyfer0618/kaldi-pytorch-rnnlm</a></p>
<p>Moreover, I will also paste all three repository there…</p>
<p>CMakeLists.txt (A)</p>
<pre><code class="lang-auto">#cmake -DCMAKE_INSTALL_PREFIX=../dist -DBLAS_LIBRARIES=/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/OpenBLAS/#libopenblas.so -DHAVE_MKL=/opt/intel/mkl -DLAPACK_LIBRARIES=/home/rakesh/#rishabh_workspace/ASR/kaldi_old/tools/lapack-3.9.0/#build/lib/liblapack.a -DPYTORCH_DIR=/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch -DCMAKE_PREFIX_PATH="/home/#rakesh/#rishabh_workspace/ASR/kaldi_old/tools/libtorch;/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch/include"  ..

cmake_minimum_required(VERSION 3.5)
set(CMAKE_VERBOSE_MAKEFILE ON)
project(kaldi)

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

#set(USE_CXX11_ABI "" CACHE STRING "Override the default GNU C++11 ABI setting")
#if(NOT ("${USE_CXX11_ABI}" STREQUAL ""))
#  if(${USE_CXX11_ABI})
#    add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
#  else()
#    add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
#  endif()
#endif()

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include(GNUInstallDirs)
include(Utils)
include(third_party/get_third_party)

# Should update cmake to a more recent version which supports FindPython3.
find_package(PythonInterp)
if(NOT PYTHON_EXECUTABLE OR PYTHON_VERSION_MAJOR LESS 3)
    message(WARNING "Needs python3 to auto-generate most CMake files, but not found. "
                    "Will try `python3` directly...")
    set(PYTHON_EXECUTABLE "python3")
endif()

message(STATUS "Running gen_cmake_skeleton.py")
execute_process(COMMAND ${PYTHON_EXECUTABLE}
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/gen_cmake_skeleton.py"
    "${CMAKE_CURRENT_SOURCE_DIR}/src"
    "--quiet"
)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INSTALL_MESSAGE LAZY) # hide "-- Up-to-date: ..."
if(BUILD_SHARED_LIBS)
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    if(WIN32)
        set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
        message(FATAL_ERROR "DLL is not supported currently")
    elseif(APPLE)
        set(CMAKE_INSTALL_RPATH "@loader_path")
    else()
        set(CMAKE_INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib")
    endif()
endif()

if(APPLE)
    # Use built-in BLAS on MacOS by default.
    set(MATHLIB "Accelerate" CACHE STRING "OpenBLAS|MKL|Accelerate")
else()
    set(MATHLIB "OpenBLAS" CACHE STRING "OpenBLAS|MKL|Accelerate")
endif()
option(KALDI_BUILD_EXE "If disabled, will make add_kaldi_executable a no-op" ON)
option(KALDI_BUILD_TEST "If disabled, will make add_kaldi_test_executable a no-op" ON)
option(KALDI_USE_PATCH_NUMBER "Use MAJOR.MINOR.PATCH format, otherwise MAJOR.MINOR" OFF)

if (KALDI_BUILD_TEST)
    include(CTest)
    enable_testing()
endif()

link_libraries(${CMAKE_DL_LIBS})

find_package(Threads)
link_libraries(Threads::Threads)

if(MATHLIB STREQUAL "OpenBLAS")
    set(BLA_VENDOR "OpenBLAS")
    find_package(LAPACK REQUIRED)
    add_definitions(-DHAVE_CLAPACK=1)
    include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tools/CLAPACK)
    link_libraries(${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
elseif(MATHLIB STREQUAL "MKL")
    set(BLA_VENDOR "Intel10_64lp")
    # find_package(BLAS REQUIRED)
    normalize_env_path(ENV{MKLROOT})
    find_package(LAPACK REQUIRED)
    add_definitions(-DHAVE_MKL=1)
    include_directories($ENV{MKLROOT}/include) # TODO: maybe not use env, idk, find_package doesnt handle includes...
    link_libraries(${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
elseif(MATHLIB STREQUAL "Accelerate")
    execute_process(COMMAND sw_vers -productVersion
        OUTPUT_VARIABLE MACOS_VERSION)
    if(MACOS_VERSION VERSION_LESS "10.12" AND MACOS_VERSION VERSION_GREATER_EQUAL "10.11")
        message(WARNING
            "**BAD WARNING**: You are using OS X El Capitan.  Some versions of this OS"
            " have a bug in the BLAS implementation that affects Kaldi."
            " After compiling, cd to matrix/ and type 'make test'.  The"
            " test will fail if the problem exists in your version."
            " Eventually this issue will be fixed by system updates from"
            " Apple.  Unexplained crashes with reports of NaNs will"
            " be caused by this bug, but some recipes will (sometimes) work."
        )
    endif()
    set(BLA_VENDOR "Apple")
    find_package(BLAS REQUIRED)
    find_package(LAPACK REQUIRED)
    add_definitions(-DHAVE_CLAPACK=1)
    link_libraries(${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
else()
    message(FATAL_ERROR "${MATHLIB} is not tested and supported, you are on your own now.")
endif()

if(MSVC)
    # Added in source, but we actually should do it in build script, whatever...
    # add_definitions(-DWIN32_LEAN_AND_MEAN=1)

    add_compile_options(/permissive- /FS /wd4819 /EHsc /bigobj)

    # some warnings related with fst
    add_compile_options(/wd4018 /wd4244 /wd4267 /wd4291 /wd4305)

    set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "")
    if(NOT DEFINED ENV{CUDAHOSTCXX})
        set(ENV{CUDAHOSTCXX} ${CMAKE_CXX_COMPILER})
    endif()
    if(NOT DEFINED CUDA_HOST_COMPILER)
        set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
    endif()
endif()

find_package(CUDA)
if(CUDA_FOUND)
    set(CUB_ROOT_DIR "/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cub")

    set(CUDA_PROPAGATE_HOST_FLAGS ON)
    set(KALDI_CUDA_NVCC_FLAGS "--default-stream=per-thread;-std=c++${CMAKE_CXX_STANDARD}")
    if(MSVC)
        list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler /permissive-,/FS,/wd4819,/EHsc,/bigobj")
        list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler /wd4018,/wd4244,/wd4267,/wd4291,/wd4305")
        if(BUILD_SHARED_LIBS)
            list(APPEND CUDA_NVCC_FLAGS_RELEASE -Xcompiler /MD)
            list(APPEND CUDA_NVCC_FLAGS_DEBUG -Xcompiler /MDd)
        endif()
    else()
    #     list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler -std=c++${CMAKE_CXX_STANDARD}")
        list(APPEND KALDI_CUDA_NVCC_FLAGS "-Xcompiler -fPIC")
    endif()
    set(CUDA_NVCC_FLAGS ${KALDI_CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS})

    add_definitions(-DHAVE_CUDA=1)
    add_definitions(-DCUDA_API_PER_THREAD_DEFAULT_STREAM=1)
    include_directories("/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64;/usr/lib/x86_64-linux-gnu/;/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/")
    link_libraries(
        ${CUDA_LIBRARIES}
        ${CUDA_CUDA_LIBRARY}
        ${CUDA_CUBLAS_LIBRARIES}
        ${CUDA_CUFFT_LIBRARIES}
        ${CUDA_curand_LIBRARY}
        ${CUDA_cusolver_LIBRARY}
        ${CUDA_cusparse_LIBRARY})

    find_package(NvToolExt REQUIRED)
    include_directories(${NvToolExt_INCLUDE_DIR})
    link_libraries(${NvToolExt_LIBRARIES})

    find_package(CUB REQUIRED)
    include_directories(${CUB_INCLUDE_DIR})
endif()

add_definitions(-DKALDI_NO_PORTAUDIO=1)

include(VersionHelper)
get_version() # this will set KALDI_VERSION and KALDI_PATCH_NUMBER
if(${KALDI_USE_PATCH_NUMBER})
    set(KALDI_VERSION "${KALDI_VERSION}.${KALDI_PATCH_NUMBER}")
endif()

#include_directories("/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch")

#link_directories("/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch")


get_third_party(openfst)
set(OPENFST_ROOT_DIR ${CMAKE_BINARY_DIR}/openfst)
include(third_party/openfst_lib_target)
link_libraries(fst)

# add all native libraries
add_subdirectory(src/base) # NOTE, we need to patch the target with version from outside
set_property(TARGET kaldi-base PROPERTY COMPILE_DEFINITIONS "KALDI_VERSION=\"${KALDI_VERSION}\"")
add_subdirectory(src/matrix)
add_subdirectory(src/cudamatrix)
add_subdirectory(src/util)
add_subdirectory(src/feat)
add_subdirectory(src/tree)
add_subdirectory(src/gmm)
add_subdirectory(src/transform)
add_subdirectory(src/sgmm2)
add_subdirectory(src/fstext)
add_subdirectory(src/hmm)
add_subdirectory(src/lm)
add_subdirectory(src/decoder)
add_subdirectory(src/lat)
add_subdirectory(src/nnet)
add_subdirectory(src/nnet2)
add_subdirectory(src/nnet3)
add_subdirectory(src/rnnlm)
add_subdirectory(src/chain)
add_subdirectory(src/ivector)
add_subdirectory(src/online)
add_subdirectory(src/online2)
add_subdirectory(src/kws)
#add_subdirectory(src/rnnlm)
#add_subdirectory(src/tfrnnlmbin)
add_subdirectory(src/itf)

if(TENSORFLOW_DIR)
    add_subdirectory(src/tfrnnlm)
    add_subdirectory(src/tfrnnlmbin)
endif()

if(PYTORCH_DIR)
    add_subdirectory(src/pyrnnlm)
    add_subdirectory(src/pyrnnlmbin)
endif()


# add all cuda libraries
if(CUDA_FOUND)
    add_subdirectory(src/cudafeat)
    add_subdirectory(src/cudadecoder)
endif()

# add all native executables
add_subdirectory(src/bin)
add_subdirectory(src/gmmbin)
add_subdirectory(src/featbin)
add_subdirectory(src/sgmm2bin)
add_subdirectory(src/fstbin)
add_subdirectory(src/lmbin)
add_subdirectory(src/latbin)
add_subdirectory(src/nnetbin)
add_subdirectory(src/nnet2bin)
add_subdirectory(src/nnet3bin)
add_subdirectory(src/rnnlmbin)
add_subdirectory(src/chainbin)
add_subdirectory(src/ivectorbin)
add_subdirectory(src/onlinebin)
add_subdirectory(src/online2bin)
add_subdirectory(src/kwsbin)

# add all cuda executables
if(CUDA_FOUND)
    add_subdirectory(src/cudafeatbin)
    add_subdirectory(src/cudadecoderbin)
endif()

include(CMakePackageConfigHelpers)
# maybe we should put this into subfolder?
configure_package_config_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake/kaldi-config.cmake.in
    ${CMAKE_BINARY_DIR}/cmake/kaldi-config.cmake
    INSTALL_DESTINATION lib/cmake/kaldi
)
write_basic_package_version_file(
    ${CMAKE_BINARY_DIR}/cmake/kaldi-config-version.cmake
    VERSION ${KALDI_VERSION}
    COMPATIBILITY AnyNewerVersion
)
install(FILES ${CMAKE_BINARY_DIR}/cmake/kaldi-config.cmake ${CMAKE_BINARY_DIR}/cmake/kaldi-config-version.cmake
    DESTINATION lib/cmake/kaldi
)
install(EXPORT kaldi-targets DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/kaldi)

</code></pre>
<p>CMakeLists.txt (B)</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(PUBLIC_HEADERS
    pytorch-rnnlm.h
)

add_library(kaldi-pyrnnlm
    pytorch-rnnlm.cc
)

#set(CMAKE_PREFIX_PATH "/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch")
#set(D_GLIBCXX_USE_CXX11_ABI,"0")
#list(APPEND CMAKE_PREFIX_PATH "/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch")


target_include_directories(kaldi-pyrnnlm PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/caffe2&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/ATen/core&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/c10/util&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/lib/python3.6/dist-packages/torch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64/stubs&gt;
)

#link_directories(/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch)

#target_include_directories(kaldi-pyrnnlm PUBLIC 
#    ${PYTORCH_DIR}
#    ${PYTORCH_DIR}/bin
#    ${PYTORCH_DIR}/include
#    ${PYTORCH_DIR}/share
#
#)

#set(CMAKE_CXX_STANDARD 14)


#find_package(Torch REQUIRED)
#find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

target_include_directories(kaldi-pyrnnlm PUBLIC 
     $&lt;BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..&gt;
     $&lt;INSTALL_INTERFACE:include/kaldi&gt;
     #/home/rakesh/rishabh_workspace/ASR/kaldi_old/tools/libtorch/include
     #/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include
)

target_compile_options(kaldi-pyrnnlm PUBLIC 
    #-lz
    #-ldl
    -fPIC
)

target_link_libraries(kaldi-pyrnnlm PUBLIC
    kaldi-lm
    kaldi-util
    kaldi-matrix
    kaldi-base
    #libc10.so
    #libc10_cuda.so
    -lz
    -ldl
    #-fPIC
    #${TORCH_LIBRARIES}
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10.so
    /usr/local/cuda/lib64/libnvrtc.so
    /usr/local/cuda/lib64/stubs/libcuda.so
    /usr/local/cuda/lib64/libnvToolsExt.so
    /usr/local/cuda/lib64/libcudart.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10_cuda.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cpu.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_python.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cuda.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libuv.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_global_deps.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtensorpipe.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libshm.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libpytorch_jni.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libnvrtc-builtins.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libfmt.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libfbjni.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_observers.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_nvrtc.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_module_test_dynamic.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_detectron_ops_gpu.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10d_cuda_test.so
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64/studs/
)



#find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

MESSAGE("TORCH LIBS ${TORCH_LIBRARIES}")

#target_link_libraries(kaldi-pyrnnlm "${TORCH_LIBRARIES}")
#set_property(TARGET kaldi-pyrnnlm PROPERTY CXX_STANDARD 14)

install(TARGETS kaldi-pyrnnlm
    EXPORT kaldi-targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES ${PUBLIC_HEADERS} DESTINATION include/kaldi/pyrnnlm)

</code></pre>
<p>CMakeLists.txt ©</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
#find_package(Torch REQUIRED)
#find_package(Torch REQUIRED PATHS /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch)

set(CMAKE_CXX_STANDARD 14)

add_executable(lattice-lmrescore-py-rnnlm lattice-lmrescore-py-rnnlm.cc)


target_include_directories(lattice-lmrescore-py-rnnlm PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/torch/csrc/api/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/caffe2&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/ATen/core&gt;
PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/include/c10/util&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/lib/python3.6/dist-packages/torch/lib&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64&gt;
#PUBLIC $&lt;BUILD_INTERFACE:/usr/local/cuda/lib64/stubs&gt;
)

target_include_directories(lattice-lmrescore-py-rnnlm PUBLIC 
     $&lt;BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..&gt;
     $&lt;INSTALL_INTERFACE:include/kaldi&gt;
)


target_link_libraries(lattice-lmrescore-py-rnnlm PUBLIC
    kaldi-pyrnnlm
    kaldi-lat
    kaldi-lm
    kaldi-util
    kaldi-matrix
    kaldi-base
    #libc10.so
    #libc10_cuda.so
    -lz
    -ldl
    #-fPIC
    #${TORCH_LIBRARIES}
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10.so
    /usr/local/cuda/lib64/libnvrtc.so
    /usr/local/cuda/lib64/stubs/libcuda.so
    /usr/local/cuda/lib64/libnvToolsExt.so
    /usr/local/cuda/lib64/libcudart.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10_cuda.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cpu.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_python.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_cuda.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libuv.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtorch_global_deps.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libtensorpipe.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libshm.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libpytorch_jni.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libnvrtc-builtins.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libfmt.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libfbjni.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_observers.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_nvrtc.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_module_test_dynamic.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libcaffe2_detectron_ops_gpu.so
    /home/rakesh/rishabh_workspace/Garbage/kaldi/tools/libtorch/lib/libc10d_cuda_test.so
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64
    #-L/home/rakesh/rishabh_workspace/Garbage/kaldi/tools/cuda/lib64/studs/
)

install(TARGETS lattice-lmrescore-py-rnnlm RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

#add_kaldi_executable(NAME lattice-lmrescore-py-rnnlm SOURCES lattice-lmrescore-py-rnnlm.cc DEPENDS kaldi-pyrnnlm kaldi-lat)
</code></pre>
<p>CMakeLists (A) is the main cmake.</p>