Add copy logic for LibTorch to avoid issues on Windows (#25556)
Summary:
This should work both on VS and Ninja.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25556
Differential Revision: D17162045
Pulled By: ezyang
fbshipit-source-id: 18c3d62e9ba93bf603f3a5310087fac77be4a974
diff --git a/docs/cpp/source/installing.rst b/docs/cpp/source/installing.rst
index 9f196dd..b16711e 100644
--- a/docs/cpp/source/installing.rst
+++ b/docs/cpp/source/installing.rst
@@ -39,6 +39,18 @@
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 11)
+ # The following code block is suggested to be used on Windows.
+ # According to https://github.com/pytorch/pytorch/issues/25457,
+ # the DLLs need to be copied to avoid memory errors.
+ if (MSVC)
+ file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
+ add_custom_command(TARGET example-app
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${TORCH_DLLS}
+ $<TARGET_FILE_DIR:example-app>)
+ endif (MSVC)
+
The implementation of our example will simply create a new `torch::Tensor` and
print it: