Skip to content

Cannot build static windows libraries  #111905

@dnns92

Description

@dnns92

🐛 Describe the bug

🐛 Describe the bug

The torch_cpu.dll is ~200 Mb, which is way too large for us. Therefore, we'd like to build torch statically. I followed the procedures hinted in the README.

These are the commands I used:

git clone https://github.com/pytorch/pytorch.git
cd pytorch && git checkout tags/v2.0.1
git submodule update --init --recursive
python -m venv .venv && .venv\Scripts\activate
pip install -r requirements.txt
pip install mkl mkl-include cmake


# additionally as found in the link above
curl https://s3.amazonaws.com/ossci-windows/mkl_2020.2.254.7z -k -O
mkdir mkl
# move 7z to mkl dir and right click, unpack here
set CMAKE_INCLUDE_PATH=D:\00_src\pytorch-fresh-install\mkl\include
set "LIB=D:\00_src\pytorch-fresh-install\mkl\lib"
# end

cd .. && mkdir build-pytorch && cd build-pytorch
cmake -DBUILD_SHARED_LIBS:BOOL=OFF -DUSE_CUDA=0 -DCMAKE_BUILD_TYPE:STRING=MinSizeRel -DCMAKE_INSTALL_PREFIX:PATH=../pytorch-install ../pytorch
# use visual studio 2019 and ALL_BUILD with MinSizeRel to build

This builds for about an hour and fails with 1200 linker errors. Is building static libs not possible anymore?

Versions

Windows 11 21H2, x64
using pip for python

cc @malfet @seemethere @peterjc123 @mszhanyi @skyline75489 @nbcsm @vladimir-aubrecht @iremyux @Blackhex @cristianPanaite

Metadata

Metadata

Assignees

Labels

module: buildBuild system issuesmodule: static linkingRelated to statically linked libtorch (we dynamically link by default)module: windowsWindows support for PyTorchtopic: binariestriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions