要将 pytorch c++ 库与 CMake 链接,您真的只需要find_package(Torch REQUIRED)
并使用
-DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch
您可以在此处下载源代码:https : //download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip CMake 教程在这里:https ://pytorch.org/cppdocs/安装.html
我有以下内容WORKSPACE
:
new_local_repository(
name = "torch",
build_file_content = all_content,
path = "third_party/libtorch",
)
这在我的BUILD
cmake_external(
name = "torch",
cache_entries = {
"CMAKE_PREFIX_PATH": "/home/jackshi/projects/third_party/libtorch",
},
lib_source = "@torch//:all",
)
当我尝试链接到它时,我得到了<dir> does not appear to contain CMakeList.txt
这是真的,但是,当您将它与 链接时,不需要find_package(Torch REQUIRED)
顶层。CMakeList.txt
CMake 寻找TorchConfig.cmake
. bazel 可以为这个包创建一个没有顶层的目标CMakeList.txt
吗?应该找TorchConfig.cmake
吧?
CMAKE_PREFIX_PATH
另外,当文件是远程的,通过获取时如何工作http_archive
,你使用~/.cache/bazel
目录吗?
谢谢!