添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
聪明伶俐的小刀  ·  理解 huggingface ...·  6 天前    · 
迷茫的勺子  ·  Python 3.14.0 beta 4 ...·  1 周前    · 
爱健身的镜子  ·  WindowManagerLayoutPar ...·  1 月前    · 
叛逆的脸盆  ·  CSS 的 scrollbar-color ...·  3 月前    · 
精明的显示器  ·  澳門日報電子版·  3 月前    · 

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 , the TorchConfig.cmake should set it up for you up when running find_package(Torch REQUIRED) .

Best regards

Thomas

It depends on how you compile your software.

If you use cmake you can do this in your CMakelist

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

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:

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

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.

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.

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

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)
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.