Fatal error: torch/script.h: No such file or directory #include <torch/script.h>

username: zhijie1996
cooked: <p>I use the libtorch-1.1 in my c++ project. But it occurs:</p>
<blockquote>
<p>[bigboy@localhost build]$ make -j 4<br>
[  2%] Built target Utilities<br>
[  3%] Building CXX object source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/<strong>/CommonLib/IbcHashMap.cpp.o<br>
[  5%] Building CXX object source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/</strong>/CommonLib/Picture.cpp.o<br>
[  5%] Building CXX object source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/<strong>/CommonLib/IntraPrediction.cpp.o<br>
[  5%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/IbcHashMap.cpp.o<br>
In file included from /home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IbcHashMap.h:43:0,<br>
from /home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IbcHashMap.cpp:41:<br>
/home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonAnalyserLib/…/CommonLib/…/CommonLib/IntraPrediction.h:47:28: fatal error: torch/script.h: No such file or directory<br>
<span class="hashtag-raw">#include</span> &lt;torch/script.h&gt;<br>
^<br>
compilation terminated.<br>
In file included from /home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IntraPrediction.cpp:38:0:<br>
/home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IntraPrediction.h:47:28: fatal error: torch/script.h: No such file or directory<br>
<span class="hashtag-raw">#include</span> &lt;torch/script.h&gt;<br>
^<br>
compilation terminated.<br>
make[2]: *** [source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/</strong>/CommonLib/IntraPrediction.cpp.o] Error 1<br>
make[2]: *** Waiting for unfinished jobs…<br>
[  6%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/IntraPrediction.cpp.o<br>
make[2]: *** [source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/<strong>/CommonLib/IbcHashMap.cpp.o] Error 1<br>
[  7%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/QuantRDOQ.cpp.o<br>
make[1]: *** [source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/all] Error 2<br>
make[1]: *** Waiting for unfinished jobs…<br>
[  8%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RdCost.cpp.o<br>
[  8%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RdCostWeightPrediction.cpp.o<br>
[  9%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Reshape.cpp.o<br>
[  9%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Rom.cpp.o<br>
[ 10%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RomLFNST.cpp.o<br>
[ 10%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RomTr.cpp.o<br>
[ 11%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/SEI.cpp.o<br>
[ 11%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/SampleAdaptiveOffset.cpp.o<br>
[ 12%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Slice.cpp.o<br>
[ 12%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/TrQuant.cpp.o<br>
[ 13%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/TrQuant_EMT.cpp.o<br>
[ 13%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Unit.cpp.o<br>
[ 14%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/UnitPartitioner.cpp.o<br>
[ 15%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/UnitTools.cpp.o<br>
[ 15%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/WeightPrediction.cpp.o<br>
[ 16%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/dtrace.cpp.o<br>
[ 16%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/dtrace_blockstatistics.cpp.o<br>
[ 17%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/CommonDefX86.cpp.o<br>
[ 17%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/InitX86.cpp.o<br>
[ 18%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/AdaptiveLoopFilter_sse41.cpp.o<br>
[ 18%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/AffineGradientSearch_sse41.cpp.o<br>
[ 19%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/Buffer_sse41.cpp.o<br>
[ 19%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/InterpolationFilter_sse41.cpp.o<br>
[ 20%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/RdCost_sse41.cpp.o<br>
[ 20%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse42/IbcHashmap_sse42.cpp.o<br>
[ 21%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/AdaptiveLoopFilter_avx.cpp.o<br>
[ 21%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/AffineGradientSearch_avx.cpp.o<br>
[ 22%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/Buffer_avx.cpp.o<br>
[ 23%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/InterpolationFilter_avx.cpp.o<br>
[ 23%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/RdCost_avx.cpp.o<br>
[ 24%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/AdaptiveLoopFilter_avx2.cpp.o<br>
[ 24%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/AffineGradientSearch_avx2.cpp.o<br>
[ 25%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/Buffer_avx2.cpp.o<br>
[ 25%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/InterpolationFilter_avx2.cpp.o<br>
[ 26%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/RdCost_avx2.cpp.o<br>
[ 26%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/</strong>/libmd5/libmd5.cpp.o<br>
[ 27%] Linking CXX static library …/…/…/…/lib/umake/gcc-4.8/x86_64/release/libCommonLib.a<br>
[ 38%] Built target CommonLib<br>
make: *** [all] Error 2</p>
</blockquote>
<p>Here is cmake output message:</p>
<blockquote>
<p>[bigboy@localhost build]$ cmake … -DCMAKE_PREFIX_PATH=/home/bigboy/huangzhijie/libtorch -DCMAKE_BUILD_TYPE=Release<br>
– The C compiler identification is GNU 4.8.5<br>
– The CXX compiler identification is GNU 4.8.5<br>
– Check for working C compiler: /usr/bin/cc<br>
– Check for working C compiler: /usr/bin/cc – works<br>
– Detecting C compiler ABI info<br>
– Detecting C compiler ABI info - done<br>
– Detecting C compile features<br>
– Detecting C compile features - done<br>
– Check for working CXX compiler: /usr/bin/c++<br>
– Check for working CXX compiler: /usr/bin/c++ – works<br>
– Detecting CXX compiler ABI info<br>
– Detecting CXX compiler ABI info - done<br>
– Detecting CXX compile features<br>
– Detecting CXX compile features - done<br>
– Setting up BBuildEnv 3.13.0.2<br>
– Looking for pthread.h<br>
– Looking for pthread.h - found<br>
– Looking for pthread_create<br>
– Looking for pthread_create - not found<br>
– Check if compiler accepts -pthread<br>
– Check if compiler accepts -pthread - yes<br>
– Found Threads: TRUE<br>
– Found OpenMP_C: -fopenmp (found version “3.1”)<br>
– Found OpenMP_CXX: -fopenmp (found version “3.1”)<br>
– Found torch: /home/bigboy/huangzhijie/libtorch/lib/libtorch.so<br>
– bb_enable_warnings:  → updating warnings flags: -Wall;-fdiagnostics-show-option;-Werror;-Wno-sign-compare;-Wno-class-memaccess<br>
– Configuring done<br>
– Generating done<br>
– Build files have been written to: /home/bigboy/huangzhijie/deepIntraVTM/build</p>
</blockquote>
<p>And I make it succeed with xcode on MacOS.</p>

username: tom
cooked: <p>Usually, the <code>find_package(Torch REQUIRED)</code> combined with <code>target_link_libraries(example-app "${TORCH_LIBRARIES}")</code> should set up the include. Did you use <code>target_link_libraries</code> with the right target?</p>
<p>Best regards</p>
<p>Thomas</p>

username: zhijie1996
cooked: <p>The structure of this project is:</p>
<blockquote>
<p>Project<br>
CMakeLists.txt<br>
Lib/<br>
CMakeLists.txt<br>
App/<br>
CMakeLists.txt<br>
where some source files in Lib/ use the libtorch. So how should I add libtorch to this project</p>
</blockquote>

username: zhijie1996
cooked: <p>Thanks a lot. I find my fault.</p>

username: Jasmeet_Kaur
cooked: <p>Hey, how did you fix this ? I am facing the same issue</p>

username: krrishabh
cooked: <p>Yes please share with us…</p>