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

I use the libtorch-1.1 in my c++ project. But it occurs:

[bigboy@localhost build]$ make -j 4
[ 2%] Built target Utilities
[ 3%] Building CXX object source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir//CommonLib/IbcHashMap.cpp.o
[ 5%] Building CXX object source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/
/CommonLib/Picture.cpp.o
[ 5%] Building CXX object source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir//CommonLib/IntraPrediction.cpp.o
[ 5%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/IbcHashMap.cpp.o
In file included from /home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IbcHashMap.h:43:0,
from /home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IbcHashMap.cpp:41:
/home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonAnalyserLib/…/CommonLib/…/CommonLib/IntraPrediction.h:47:28: fatal error: torch/script.h: No such file or directory
#include <torch/script.h>
^
compilation terminated.
In file included from /home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IntraPrediction.cpp:38:0:
/home/bigboy/huangzhijie/deepIntraVTM/source/Lib/CommonLib/IntraPrediction.h:47:28: fatal error: torch/script.h: No such file or directory
#include <torch/script.h>
^
compilation terminated.
make[2]: *** [source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/
/CommonLib/IntraPrediction.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs…
[ 6%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/IntraPrediction.cpp.o
make[2]: *** [source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir//CommonLib/IbcHashMap.cpp.o] Error 1
[ 7%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/QuantRDOQ.cpp.o
make[1]: *** [source/Lib/CommonAnalyserLib/CMakeFiles/CommonAnalyserLib.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs…
[ 8%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RdCost.cpp.o
[ 8%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RdCostWeightPrediction.cpp.o
[ 9%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Reshape.cpp.o
[ 9%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Rom.cpp.o
[ 10%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RomLFNST.cpp.o
[ 10%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/RomTr.cpp.o
[ 11%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/SEI.cpp.o
[ 11%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/SampleAdaptiveOffset.cpp.o
[ 12%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Slice.cpp.o
[ 12%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/TrQuant.cpp.o
[ 13%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/TrQuant_EMT.cpp.o
[ 13%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/Unit.cpp.o
[ 14%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/UnitPartitioner.cpp.o
[ 15%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/UnitTools.cpp.o
[ 15%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/WeightPrediction.cpp.o
[ 16%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/dtrace.cpp.o
[ 16%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/dtrace_blockstatistics.cpp.o
[ 17%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/CommonDefX86.cpp.o
[ 17%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/InitX86.cpp.o
[ 18%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/AdaptiveLoopFilter_sse41.cpp.o
[ 18%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/AffineGradientSearch_sse41.cpp.o
[ 19%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/Buffer_sse41.cpp.o
[ 19%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/InterpolationFilter_sse41.cpp.o
[ 20%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse41/RdCost_sse41.cpp.o
[ 20%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/sse42/IbcHashmap_sse42.cpp.o
[ 21%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/AdaptiveLoopFilter_avx.cpp.o
[ 21%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/AffineGradientSearch_avx.cpp.o
[ 22%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/Buffer_avx.cpp.o
[ 23%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/InterpolationFilter_avx.cpp.o
[ 23%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx/RdCost_avx.cpp.o
[ 24%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/AdaptiveLoopFilter_avx2.cpp.o
[ 24%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/AffineGradientSearch_avx2.cpp.o
[ 25%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/Buffer_avx2.cpp.o
[ 25%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/InterpolationFilter_avx2.cpp.o
[ 26%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/x86/avx2/RdCost_avx2.cpp.o
[ 26%] Building CXX object source/Lib/CommonLib/CMakeFiles/CommonLib.dir/
/libmd5/libmd5.cpp.o
[ 27%] Linking CXX static library …/…/…/…/lib/umake/gcc-4.8/x86_64/release/libCommonLib.a
[ 38%] Built target CommonLib
make: *** [all] Error 2

Here is cmake output message:

[bigboy@localhost build]$ cmake … -DCMAKE_PREFIX_PATH=/home/bigboy/huangzhijie/libtorch -DCMAKE_BUILD_TYPE=Release
– The C compiler identification is GNU 4.8.5
– The CXX compiler identification is GNU 4.8.5
– 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
– Setting up BBuildEnv 3.13.0.2
– Looking for pthread.h
– Looking for pthread.h - found
– Looking for pthread_create
– Looking for pthread_create - not found
– Check if compiler accepts -pthread
– Check if compiler accepts -pthread - yes
– Found Threads: TRUE
– Found OpenMP_C: -fopenmp (found version “3.1”)
– Found OpenMP_CXX: -fopenmp (found version “3.1”)
– Found torch: /home/bigboy/huangzhijie/libtorch/lib/libtorch.so
– bb_enable_warnings: -> updating warnings flags: -Wall;-fdiagnostics-show-option;-Werror;-Wno-sign-compare;-Wno-class-memaccess
– Configuring done
– Generating done
– Build files have been written to: /home/bigboy/huangzhijie/deepIntraVTM/build

And I make it succeed with xcode on MacOS.

1 Like

Usually, the find_package(Torch REQUIRED) combined with target_link_libraries(example-app "${TORCH_LIBRARIES}") should set up the include. Did you use target_link_libraries with the right target?

Best regards

Thomas

1 Like

The structure of this project is:

Project
CMakeLists.txt
Lib/
CMakeLists.txt
App/
CMakeLists.txt
where some source files in Lib/ use the libtorch. So how should I add libtorch to this project

Thanks a lot. I find my fault.

Hey, how did you fix this ? I am facing the same issue

Yes please share with us…