1. 官网下载libtorch库

PyTorch

<aside> 💡 CentOS 7上由于glibc库版本较低,只能下载 Pre-cxx11 ABI版本,并且需要gcc 5以上版本

</aside>

<aside> 💡 本机CentOS虚拟机里通过yum安装了gcc 5.3.0可以编译运行

</aside>

yum install -y centos-release-scl

yum install -y devtoolset-4-gcc devtoolset-4-gcc-c++

2. cmake设置

编辑CMakeList.txt如下:

NOTE:Precxx-11 ABI版本须将CXX_STANDARD改为11

执行cmake命令:

NOTE:注意文件结构,cmake命令 -DCMAKE_PREFIX_PATH指定libtorch所在目录 参数为CMakeList.txt所在目录,build可直接执行make

参考:

  1. https://pytorch.org/cppdocs/installing.html

  2. https://www.pytorchtutorial.com/category/tutorial-cpp-api/

  3. http://sixerwang.github.io/2019/04/17/pytorch-cpp-api/

    PyTorch C++ API初探 | Dannyw's Blog

  4. CentOS 7 上升级/安装gcc

    CentOS 7上升级/安装gcc

  5. libtorch在Windows上部署

    https://oldpan.me/archives/pytorch-windows-libtorch