LOADING A TORCHSCRIPT CMakeLists build error!

Hi guys. I follow the tutorial below.

https://pytorch.org/tutorials/advanced/cpp_export.html

I download libtorch/ and below is my CMakeLists.txt

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(custom_ops)

find_package(Torch REQUIRED)

add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

during cmake build I got an error below

pytorch_TorchScript/
 ㄴlibtorch/
 ㄴ build/
 ㄴexample-app.cpp

$ cd build
$ cmake -DCMAKE_PREFIX_PATH='/home/dhpark/pytorch_TorchScript/libtorch' ..

Error)

pytorch_TorchScript/build# cmake -DCMAKE_PREFIX_PATH='/home/dhpark/pytorch_TorchScript/libtorch' ..
-- Caffe2: CUDA detected: 11.6
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 11.6
-- Found cuDNN: v8.5.0  (include: /usr/local/cuda/include, library: /usr/local/cuda/lib64/libcudnn.so)
-- /usr/local/cuda/lib64/libnvrtc.so shorthash is 4dd39364
-- Autodetected CUDA architecture(s):  8.6 8.6 8.6 8.6
-- Added CUDA NVCC flags for: -gencode;arch=compute_86,code=sm_86
CMake Warning at libtorch/share/cmake/Torch/TorchConfig.cmake:22 (message):
  static library c10_LIBRARY-NOTFOUND not found.
Call Stack (most recent call first):
  libtorch/share/cmake/Torch/TorchConfig.cmake:70 (append_torchlib_if_found)
  CMakeLists.txt:8 (find_package)


CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find Torch (missing: TORCH_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  libtorch/share/cmake/Torch/TorchConfig.cmake:190 (find_package_handle_standard_args)
  CMakeLists.txt:8 (find_package)

I think the reason of the problem is
’ static library c10_LIBRARY-NOTFOUND not found.’

I don’t know how to solve it.

Can anyone help ??

Thanks alot.

It seems that cmake has trouble finding libtorch in your setup. Make sure the libtorch folder contains all expected files and maybe move it out of your project dir.

I met the same problem, did you solve this problem?