# Where to find \<torch/torch.h\>?

**URL:** <https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908>\
**Category:** C++\
**Created:** [November 4, 2019, 1:20am UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908 "2019-11-04T01:20:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Zheng](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/peter_zheng/32/17262_2.png) [@Peter\_Zheng](https://discuss.pytorch.org/u/Peter_Zheng)\
**Post date:** [November 4, 2019, 1:20am UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/1 "2019-11-04T01:20:39Z")

</div>

I succeed in compiling the code with cmake directly, but when I use vscode for editing, it always get error message with \<torch/torch.h\> not found. How can I get it?

---

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [November 4, 2019, 6:52am UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/2 "2019-11-04T06:52:58Z")

</div>

Hi,

you need to add the somewhat hidden `<installation dir>/include/torch/csrc/api/include` to the includes.  
If you create the CMakeLists.txt as in [the example](https://pytorch.org/cppdocs/installing.html), the TorchConfig.cmake should set it up for you up when running `find_package(Torch REQUIRED)`.

Best regards

Thomas

---

<div class="post-metadata">

**Author:** ![Peter\_Zheng](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/peter_zheng/32/17262_2.png) [@Peter\_Zheng](https://discuss.pytorch.org/u/Peter_Zheng)\
**Post date:** [November 7, 2019, 11:49am UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/3 "2019-11-07T11:49:07Z")

</div>

It’s works!!  
Thanks!!😀

---

<div class="post-metadata">

**Author:** ![Roger\_Aylagas](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/roger_aylagas/32/21529_2.png) [@Roger\_Aylagas](https://discuss.pytorch.org/u/Roger_Aylagas)\
**Post date:** [March 10, 2020, 11:35am UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/4 "2020-03-10T11:35:44Z")

</div>

Hi I am starting using Torch in c++ and I do not know what are you refering as adding the folder to the includes. Sorry if this is a very basic question.

---

<div class="post-metadata">

**Author:** ![Hartbook](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hartbook/32/19990_2.png) [@Hartbook](https://discuss.pytorch.org/u/Hartbook)\
**Post date:** [March 10, 2020, 12:23pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/5 "2020-03-10T12:23:57Z")

</div>

It depends on how you compile your software.

If you use cmake you can do this in your CMakelist

```auto
find_package(Torch REQUIRED)
include_directories(SYSTEM ${TORCH_INCLUDE_DIRS})

```

---

<div class="post-metadata">

**Author:** ![ilhem](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/i/90ced4/32.png) [@ilhem](https://discuss.pytorch.org/u/ilhem)\
**Post date:** [June 20, 2020, 5:45pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/6 "2020-06-20T17:45:27Z")

</div>

hi, i create CMakeLists.txt as in [the example](https://pytorch.org/cppdocs/installing.html) and I do the configuration but appearing an error is : torch\_dir not found ? what do i do for succeful compiling .

---

<div class="post-metadata">

**Author:** ![naveen139](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naveen139/32/26682_2.png) [@naveen139](https://discuss.pytorch.org/u/naveen139)\
**Post date:** [July 14, 2020, 6:59am UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/7 "2020-07-14T06:59:08Z")

</div>

Add this line to your project’s CMakeLists.txt file.

```auto
set(CMAKE_PREFIX_PATH "<libtorch-path>/share/cmake/Torch")

```

---

<div class="post-metadata">

**Author:** ![ambiguity](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ambiguity/32/29184_2.png) [@ambiguity](https://discuss.pytorch.org/u/ambiguity)\
**Post date:** [September 25, 2020, 3:17pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/8 "2020-09-25T15:17:41Z")

</div>

Hi,

After I linked `<installation dir>/include/torch/csrc/api/include` to the includes, with command line `sudo ln -s /usr/local/Cellar/libtorch/1.6.0_1/include/torch/csrc/api/include/torch torch` in the directory `/usr/local/include`, my vscode and ycm of vim still can’t work. Am I wrong?

---

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [September 25, 2020, 3:50pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/9 "2020-09-25T15:50:55Z")

</div>

I’m not sure symlinking is a good way to go about it, as you need several directories to be set up that contain torch (i.e. torch/include and torch/csrc/api/include).

---

<div class="post-metadata">

**Author:** ![DineshRajan\_T](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dineshrajan_t/32/33253_2.png) [@DineshRajan\_T](https://discuss.pytorch.org/u/DineshRajan_T)\
**Post date:** [January 9, 2021, 5:53pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/10 "2021-01-09T17:53:53Z")

</div>

Did this work for you @naveen139?

---

<div class="post-metadata">

**Author:** ![naveen139](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naveen139/32/26682_2.png) [@naveen139](https://discuss.pytorch.org/u/naveen139)\
**Post date:** [January 9, 2021, 6:21pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/11 "2021-01-09T18:21:12Z")

</div>

Ignore that, that was for some workaround to get early alpha package working. In recent versions, you don’t need to do that. You can simply do below:

```auto
list(APPEND CMAKE_PREFIX_PATH "<libtorch-path>")
find_package(Torch REQUIRED)

```

---

<div class="post-metadata">

**Author:** ![DineshRajan\_T](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dineshrajan_t/32/33253_2.png) [@DineshRajan\_T](https://discuss.pytorch.org/u/DineshRajan_T)\
**Post date:** [January 9, 2021, 6:24pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/12 "2021-01-09T18:24:04Z")

</div>

Should I add it in the CMakeLists.txt file or in TorchConfig.cmake?

---

<div class="post-metadata">

**Author:** ![naveen139](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naveen139/32/26682_2.png) [@naveen139](https://discuss.pytorch.org/u/naveen139)\
**Post date:** [January 9, 2021, 6:26pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/13 "2021-01-09T18:26:35Z")

</div>

Yes, in your root project folder’s `CMakeLists.txt`. Don’t make any changes to `TorchConfig.cmake`

but, if you are encountering an error `missing dll(s)` on windows, here is an workaround.

```auto
file(GLOB TORCH_DLLS ${TORCH_INSTALL_PREFIX}/lib/*.dll)
 add_custom_command(TARGET <exe-name> POST_BUILD
   COMMAND ${CMAKE_COMMAND} -E copy
   ${TORCH_DLLS}
   ${CMAKE_CURRENT_BINARY_DIR}
   DEPENDS <exe-name>
 )

```

this copies dlls into path of your executable.

---

<div class="post-metadata">

**Author:** ![DineshRajan\_T](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dineshrajan_t/32/33253_2.png) [@DineshRajan\_T](https://discuss.pytorch.org/u/DineshRajan_T)\
**Post date:** [January 9, 2021, 6:39pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/14 "2021-01-09T18:39:32Z")

</div>

This is my CMakeLists.txt. I am still getting the same error, which is "fatal error C1083: Cannot open include file: ‘torch/torch.h’ "

```auto
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)

find_package(Torch REQUIRED)
list(APPEND CMAKE_PREFIX_PATH "<my-libtorch-path>")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

if (MSVC)
  file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  add_custom_command(TARGET example-app
                     POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E copy
                     ${TORCH_DLLS}
                     ${CMAKE_CURRENT_BINARY_DIR}
                     DEPENDS example-app)
endif (MSVC)

```

---

<div class="post-metadata">

**Author:** ![naveen139](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naveen139/32/26682_2.png) [@naveen139](https://discuss.pytorch.org/u/naveen139)\
**Post date:** [January 9, 2021, 6:45pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/15 "2021-01-09T18:45:32Z")

</div>

You forgot to add include paths.

```auto
include_directories(
  "${TORCH_INCLUDE_DIRS}"
)

```

---

<div class="post-metadata">

**Author:** ![DineshRajan\_T](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dineshrajan_t/32/33253_2.png) [@DineshRajan\_T](https://discuss.pytorch.org/u/DineshRajan_T)\
**Post date:** [January 9, 2021, 6:48pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/16 "2021-01-09T18:48:18Z")

</div>

where should I include that? Can you be more specific? I am a beginner dealing with CMake files.

---

<div class="post-metadata">

**Author:** ![naveen139](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naveen139/32/26682_2.png) [@naveen139](https://discuss.pytorch.org/u/naveen139)\
**Post date:** [January 9, 2021, 6:50pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/17 "2021-01-09T18:50:21Z")

</div>

Sure. Just add it in the same file, but before `add_executable`.

---

<div class="post-metadata">

**Author:** ![DineshRajan\_T](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dineshrajan_t/32/33253_2.png) [@DineshRajan\_T](https://discuss.pytorch.org/u/DineshRajan_T)\
**Post date:** [January 10, 2021, 5:31pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/18 "2021-01-10T17:31:54Z")

</div>

Hi @naveen139, I installed the torch via pip. Now that how should I include the directories?

---

<div class="post-metadata">

**Author:** ![naveen139](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/naveen139/32/26682_2.png) [@naveen139](https://discuss.pytorch.org/u/naveen139)\
**Post date:** [January 10, 2021, 5:55pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/19 "2021-01-10T17:55:55Z")

</div>

I don’t understand what you are trying to achieve. Are you trying to use libtorch to be able to call from python?

---

<div class="post-metadata">

**Author:** ![DineshRajan\_T](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/dineshrajan_t/32/33253_2.png) [@DineshRajan\_T](https://discuss.pytorch.org/u/DineshRajan_T)\
**Post date:** [January 10, 2021, 6:03pm UTC](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908/20 "2021-01-10T18:03:08Z")

</div>

I am trying this basic one…

```auto
https://pytorch.org/cppdocs/installing.html

```

And I get the error `"fatal error C1083: Cannot open include file: 'torch/torch.h': No such file or directory "`  
I know I am missing the torch.h and I don’t where should I add that.

[Next page](https://discuss.pytorch.org/t/where-to-find-torch-torch-h/59908.md?page=2)
