# cmake를 사용하는 과정에서 에러가 발생합니다

**URL:** <https://discuss.pytorch.kr/t/cmake/324>\
**Category:** 묻고 답하기\
**Tags:** 파이토치\
**Created:** [6월 6, 2022, 7:09오전 UTC](https://discuss.pytorch.kr/t/cmake/324 "2022-06-06T07:09:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pyqci99](https://discuss.pytorch.kr/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@pyqci99](https://discuss.pytorch.kr/u/pyqci99)\
**Post date:** [6월 6, 2022, 7:09오전 UTC](https://discuss.pytorch.kr/t/cmake/324/1 "2022-06-06T07:09:26Z")

</div>

> **[C++에서 TorchScript 모델 로딩하기](https://tutorials.pytorch.kr/advanced/cpp_export.html)**
>
> PyTorch의 이름에서 알 수 있듯이 PyTorch는 Python 프로그래밍 언어를 기본 인터페이스로 하고 있습니다. Python은 동적성과 신속한 이터레이션이 필요한 상황에 적합하고 선호되는 언어입니다. 하지만 마찬가지로 이러한 Python의 특징들이 Python을 사용하기 적합하지 않게 만드는 상황도 많이 발생합니다. Python을 사용하기 적합하지 않은 대표적인 예로 상용 환경이 있습니다. 상용 환경에서는 짧은 지연시간이 중요하고...

이 튜토리얼을 이용해서 파이토치 모델을 C++로 변환하는 중입니다만  
cmake를 이용하는 과정에서  
cmake -DCMAKE\_PREFIX\_PATH=/path/to/libtorch .. 명령어를 입력할 때  
TorchConfig.cmake torch-config.cmake를 찾을 수 없다는 에러가 계속 반복됩니다  
깃허브나 스택오버플로의 글을 읽어봐도 완전히 에러가 해결된 해법은 찾지 못하고 있습니다.  
아래는 로그입니다  
-- Building for: Visual Studio 17 2022  
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.  
-- The C compiler identification is MSVC 19.32.31329.0  
-- The CXX compiler identification is MSVC 19.32.31329.0  
-- Detecting C compiler ABI info  
-- Detecting C compiler ABI info - done  
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped  
-- Detecting C compile features  
-- Detecting C compile features - done  
-- Detecting CXX compiler ABI info  
-- Detecting CXX compiler ABI info - done  
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped  
-- Detecting CXX compile features  
-- Detecting CXX compile features - done  
CMake Error at CMakeLists.txt:4 (find\_package):  
By not providing "FindTorch.cmake" in CMAKE\_MODULE\_PATH this project has  
asked CMake to find a package configuration file provided by "Torch", but  
CMake did not find one.

Could not find a package configuration file provided by "Torch" with any of  
the following names:

```
TorchConfig.cmake
torch-config.cmake

```

Add the installation prefix of "Torch" to CMAKE\_PREFIX\_PATH or set  
"Torch\_DIR" to a directory containing one of the above files. If "Torch"  
provides a separate development package or SDK, be sure it has been  
installed.

-- Configuring incomplete, errors occurred!  
See also "C:/Users/com/source/repos/luda1/luda1/CMakeFiles/CMakeOutput.log".  
libtorch의 파일을 찾지 못하는듯한데, 해결방법이 있을까요 ??

---

<div class="post-metadata">

**Author:** ![Sung\_Sue\_Hwang](https://discuss.pytorch.kr/user_avatar/discuss.pytorch.kr/sung_sue_hwang/32/24_2.png) [@Sung\_Sue\_Hwang](https://discuss.pytorch.kr/u/Sung_Sue_Hwang)\
**Post date:** [6월 6, 2022, 3:23오후 UTC](https://discuss.pytorch.kr/t/cmake/324/2 "2022-06-06T15:23:18Z")

</div>

위에서 입력하신 아래 명령어를

> [@pyqci99](#):
>
> cmake -DCMAKE\_PREFIX\_PATH=/path/to/libtorch

혹시 "/path/to/libtorch"를 입력하신 것은 아닌가요?  
만약 그러시면 libtorch를 다운 받으신 다음 자신의 경로를 입력하시기 바랍니다.

---

<div class="post-metadata">

**Author:** ![pyqci99](https://discuss.pytorch.kr/letter_avatar_proxy/v4/letter/p/e79b87/32.png) [@pyqci99](https://discuss.pytorch.kr/u/pyqci99)\
**Post date:** [6월 7, 2022, 7:43오전 UTC](https://discuss.pytorch.kr/t/cmake/324/3 "2022-06-07T07:43:34Z")

</div>

libtorch 들어가있는 폴더 경로 입력하였습니다

---

<div class="post-metadata">

**Author:** ![Taeyoung96](https://discuss.pytorch.kr/user_avatar/discuss.pytorch.kr/taeyoung96/32/68_2.png) [@Taeyoung96](https://discuss.pytorch.kr/u/Taeyoung96)\
**Post date:** [6월 7, 2022, 9:00오전 UTC](https://discuss.pytorch.kr/t/cmake/324/4 "2022-06-07T09:00:02Z")

</div>

CMakelist.txt.에서  
`find_package(Torch REQUIRED)` 부분을  
`find_package(Torch)` 로 바꾸고 컴파일하면 어떻게 되나요?

---

<div class="post-metadata">

**Author:** ![Sung\_Sue\_Hwang](https://discuss.pytorch.kr/user_avatar/discuss.pytorch.kr/sung_sue_hwang/32/24_2.png) [@Sung\_Sue\_Hwang](https://discuss.pytorch.kr/u/Sung_Sue_Hwang)\
**Post date:** [6월 7, 2022, 4:02오후 UTC](https://discuss.pytorch.kr/t/cmake/324/5 "2022-06-07T16:02:07Z")

</div>

제 컴퓨터에 Visual Studio 2022를 설치 + cmake 설치 + libtorch 다운 & 압축 풀기

- 샘플코드 이후에 cmake를 실행한 예시 입니다.  
 ![image](https://discuss.pytorch.kr/uploads/default/original/1X/c410b4fa35dce8e5788df1dba02f8fa689f0bd7b.png)  
아래 CMakeLists는 동일 합니다.  
 ![image](https://discuss.pytorch.kr/uploads/default/original/1X/a675e95e04cf8a9f9a7066bf1dac69f385ddaf1b.png)

일단 저는 문제가 없었고 결국 경로 문제가 아닐까 하는데요

1. libtorch의 경로가 cmake를 실행하는 폴더 아래는 아닌지
2. 경로 입력이 오타나 특수 기호 등 다른 문제가 있는것은 아닌지 확인이 필요합니다.

---

<div class="post-metadata">

**Author:** ![wonjaegang](https://discuss.pytorch.kr/letter_avatar_proxy/v4/letter/w/c4cdca/32.png) [@wonjaegang](https://discuss.pytorch.kr/u/wonjaegang)\
**Post date:** [10월 26, 2022, 5:36오전 UTC](https://discuss.pytorch.kr/t/cmake/324/6 "2022-10-26T05:36:13Z")

</div>

[https://github.com/pytorch/pytorch/issues/12449](https://github.com/pytorch/pytorch/issues/12449)  
저는 여기서 ganler님의 답변 참고해서 해결했습니다.
