Repository: pytorch
Issue: LNK2019 error after static compilation of Libtorch
Labels: module: build,triaged

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->I
I have statically build libtorch 1.6.0 successfully using the below commmands. After that when I try to link libtorch to the project I get the LNK2019 Unresolved External Symbol error?Is there anyway to solve this
`Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr & __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr const &)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@AEBU01@@Z) referenced in function "public: struct c10::ivalue::Object & __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &)" (??4Object@ivalue@c10@@QEAAAEAU012@AEBU012@@Z)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1	
`
`Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr & __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr &&)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@$$QEAU01@@Z) referenced in function "public: struct c10::ivalue::Object & __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object &&)" (??4Object@ivalue@c10@@QEAAAEAU012@$$QEAU012@@Z)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1	
`
`Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol "__declspec(dllimport) protected: class c10::intrusive_ptr_target & __cdecl c10::intrusive_ptr_target::operator=(class c10::intrusive_ptr_target const &)" (__imp_??4intrusive_ptr_target@c10@@IEAAAEAV01@AEBV01@@Z) referenced in function "public: struct c10::ivalue::Object & __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &)" (??4Object@ivalue@c10@@QEAAAEAU012@AEBU012@@Z)	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\test_pytorch	C:\Users\dawachat\Desktop\test_pytorch\out\build\x64-Rel\example-app-debug.cpp.obj	1	
`
These are the errors.
The libraries I am linking are

> Caffe2_perfkernels_avx.lib
Caffe2_perfkernels_avx2.lib
Caffe2_perfkernels_avx512.lib
c10.lib
caffe2_protos.lib
clog.lib
cpuinfo.lib
cpuinfo_internals.lib
foxi_loader.lib
libprotobuf-lite.lib
libprotobuf.lib
libprotoc.lib
dnnl.lib
onnx.lib
onnx_proto.lib

>/WHOLEARCHIVE:
torch.lib
torch_cpu.lib


## To Reproduce

Steps to reproduce the behavior:

set BUILD_SHARED_LIBS=OFF
set BUILD_TEST=OFF
set BUILD_CAFFE2_OPS=OFF 
set BUILD_PYTHON=False
set CAFFE2_USE_MSVC_STATIC_RUNTIME=ON
set MSVC_Z7_OVERRIDE=OFF
set USE_CUDA=OFF
set USE_FBGEMM=OFF

py tools\build_libtorch.py

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->
It should link correctly.
## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```

 - PyTorch Version (e.g., 1.0): 1.6.0
 - OS (e.g., Linux): windows
 - How you installed PyTorch (`conda`, `pip`, source): source
 - Build command you used (if compiling from source):
 - Python version:3.8.3
 - CUDA/cuDNN version: No
 - GPU models and configuration:
 - Any other relevant information: Using msvc in windows


## Additional context

<!-- Add any other context about the problem here. -->


cc @ezyang @seemethere @malfet @walterddr @peterjc123 @maxluk @nbcsm @guyang3532 @gunandrose4u @smartcat2010 @mszhanyi