libtorch建议直接采用官方的预编译版本,对应好torchvision版本做编译。
1. libtorch预编译版本下载
libtorch官方下载地址
Pybind11编译
git clone https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
(base) PS E:\project\pybind11-2.13.1> cd .\build\
(base) PS E:\project\pybind11-2.13.1\build> cmake -DPYBIND11_TEST=OFF -DCMAKE_INSTALL_PREFIX="..\install" ..
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22621.
-- pybind11 v2.13.1
-- CMake 3.30.0-rc4
-- Python 3.11.4
-- pybind11::lto enabled
-- pybind11::thin_lto enabled
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: E:/project/pybind11-2.13.1/build
(base) PS E:\project\pybind11-2.13.1\build> cmake --install .
-- Install configuration: "Release"
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/attr.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/buffer_info.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/cast.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/chrono.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/common.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/complex.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail/class.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail/common.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail/descr.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail/init.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail/internals.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail/typeid.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/detail/type_caster_base.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/eigen
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/eigen/common.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/eigen/matrix.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/eigen/tensor.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/eigen.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/embed.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/eval.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/functional.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/gil.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/gil_safe_call_once.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/iostream.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/numpy.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/operators.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/options.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/pybind11.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/pytypes.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/stl
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/stl/filesystem.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/stl.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/stl_bind.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/type_caster_pyobject_ptr.h
-- Installing: E:/project/pybind11-2.13.1/install/include/pybind11/typing.h
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/pybind11Config.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/pybind11ConfigVersion.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/FindPythonLibsNew.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/pybind11Common.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/pybind11Tools.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/pybind11NewTools.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/pybind11GuessPythonExtSuffix.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/cmake/pybind11/pybind11Targets.cmake
-- Installing: E:/project/pybind11-2.13.1/install/share/pkgconfig/pybind11.pc
zlib编译
git clone https://github.com/madler/zlib.git
cd zlib
zlib
提供了vc17的工程,在zlib\contrib\vstudio\vc17\zlibvc.sln
中,注意编译x64版本的库。注意直接编译会报错,在VERSION前面增加一个;注释掉这一行即可
生成开始于 18:23...
1>------ 已启动生成: 项目: zlibvc, 配置: Release x64 ------
1> 正在创建库 x64\ZlibDllRelease\zlibwapi.lib 和对象 x64\ZlibDllRelease\zlibwapi.exp
1>正在生成代码
1>267 of 268 functions (99.6%) were compiled, the rest were copied from previous compilation.
1> 0 functions were new in current compilation
1> 0 functions had inline decision re-evaluated but remain unchanged
1>已完成代码的生成
1>zlibvc.vcxproj -> E:\project\zlib\contrib\vstudio\vc17\x64\ZlibDllRelease\zlibwapi.dll
========== 生成: 1 成功,0 失败,0 最新,0 已跳过 ==========
========== 生成 于 18:23 完成,耗时 00.644 秒 ==========
libpng编译
git clone https://github.com/pnggroup/libpng.git
libpng提供了visualstudio的工程,在libpng\projects\vstudio\vstudio.sln
中,注意切换平台为x64。
注意:vstudio默认认为zlib工程文件夹与libpng同级,注意上一步操作如果不是git clone 下来的库,需要修改文件夹名为zlib。同样主意编译x64版本的库。
2>All 573 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
2>已完成代码的生成
2>libpng.vcxproj -> E:\project\libpng-1.6.43\projects\vstudio\x64\Release\libpng.dll
2>已完成生成项目“libpng.vcxproj”的操作。
========== 生成: 2 成功,0 失败,1 最新,0 已跳过 ==========
========== 生成 于 18:29 完成,耗时 02.949 秒 ==