Libtorch static library

wolfviking0: <p>Hello I am building libtorch has static library. But now I am struggling to have a binary code running properly.</p>
<p>So I try few stuff:</p>
<ol>
<li>
<p>Just linking my main.cpp with all the static library from libtorch<br>
–&gt; Result : abort libc++aby.dylib: terminating with uncaught exception of type c10::bad_optionnal_access</p>
</li>
<li>
<p>I was suspecting it could be because I need to use whole_archive, I put all the library with whole_archive but few issue:<br>
–&gt; undefined reference of onnxifi_loader<br>
2.1) I copy the missing libonnxifi_loader.a<br>
–&gt; exec format error: my_torch_sample</p>
</li>
</ol>
<p>I am not sure what should I do next, any suggestion how to use Libtorch as a static library ?</p>
<p>Thanks</p>

wolfviking0: <p>After fighting few hours, I finally figure out the trouble with the static library of pytorch.<br>
The main trouble was the --force-load or --whole-archive need to be apply on some specific library not only torch but not all of them.</p>
<p>Now I am able to run libtorch with and without Cuda over:<br>
OSX Catalina (CPU)<br>
OSX High Sierra (CPU/GPU)<br>
Ubuntu 18.04 (CPU/GPU)</p>
<p>I am facing another issue now on Windows. The build failed because of this error :<br>
<code>error C2338: CopyToCPU requires fundamental types</code><br>
If someone has an idea how to fix it, that will be very nice.</p>
<p>Thanks</p>

wolfviking0: <p>After looking to the pytorch issues it seems there is a patch for this one but not inside the latest release.</p>
<p>I apply it and its now build fine but still failed to link because of size:</p>
<p>Fatal error LNK1248: image size exceeds maximum allowable</p>
<p>I am building with ninja in release, I am not sure how I can fix this one, any suggestion.</p>
<p>Thanks</p>

peterjc123: <aside class="quote no-group" data-username="wolfviking0" data-post="3" data-topic="73178">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/wolfviking0/48/20683_2.png" class="avatar"> wolfviking0:</div>
<blockquote>
<p>LNK1248</p>
</blockquote>
</aside>
<p>Would you please try whether <code>set MSVC_Z7_OVERRIDE=OFF</code> works?</p>

wolfviking0: <p>Hi <a class="mention" href="/u/peterjc123">@peterjc123</a>,</p>
<p>I try to set MSVC_Z7 but still have the same issue, finally I am building torch using MinSizeRel and it seems to be working fine, I was able to build a cpu version of torch for windows 10.</p>
<p>Currently building the GPU version.</p>
<p>Thanks</p>

wolfviking0: <p>I was finally able to build my static windows version of torch using cuda.<br>
Unfortunately now I have another issue.</p>
<p>If I link the library normally I can run my sample but I received an exception from CUDA when I try to use it. It make sense because I need to use the link flag WHOLE_ARCHIVE.</p>
<p>But if I use it with my static library torch. When I try to launch my executable I have a direct segfault.</p>
<p>Someone has an idea why torch will give me a segfault like that, I will try to have mode info why is giving a segfault but if someone have an idea it will be really useful.</p>
<p>Thanks</p>

santhiya-v: <p>I am also facing same issue, could you please share how you are loading libraries (with options)?</p>

stakemura: <p>Would you like to share how to build Libtorch static libraries?<br>
As <a href="https://github.com/pytorch/pytorch/issues/21737" rel="nofollow noopener">Static linking master bug #21737</a> indicates, not a few user are interested in this issue.</p>

wolfviking0: <p>Hi Guys, sorry to take so long before giving a response, I was off for few weeks, but here I am back.</p>
<p>So I am currently building CPU and GPU version of Torch as static library.</p>
<p>First of all the first time I try I was using lib torch 1.3.1 and 1.4 but same if I was able to build successfully my perf was extremely bad so I decide to move to a more recent version:</p>
<p>So I am currently using this checkout 246b208e4f60d6894ffaeeed8c9746e331fa6f6f : I am almost sure a most recent version should work too.</p>
<p>In order to build I try both calling CMake directly and using Python script and both work for me:</p>
<pre><code class="lang-auto">-DBUILD_CAFFE2_MOBILE=OFF;
-DBUILD_SHARED_LIBS=OFF;
-DCAFFE2_USE_MSVC_STATIC_RUNTIME=ON;
-DMSVC_Z7_OVERRIDE=OFF;
-DUSE_CUDA=OFF/ON;
-DBUILD_PYTHON=OFF;
-DBUILD_TEST=OFF;
</code></pre>
<p>One important point I decide to use Visual Studio 2019 too build, when using the script python I decide to force two part:</p>
<ol>
<li>Disable python : <a href="https://github.com/pytorch/pytorch/blob/fc4dfbf7009e42bbf00a4b9a5f91520478d63b0f/setup.py#L313" rel="nofollow noopener">HERE</a>
</li>
<li>Force Visual studio 2019: <a href="https://github.com/pytorch/pytorch/blob/bfa5070cbcfb876508f84b8a42dd637268cead79/tools/setup_helpers/cmake.py#L179" rel="nofollow noopener">HERE</a>
</li>
</ol>
<p>I am sure there are better way to bypass those value, but for me it was enough like that.</p>
<p>After that the build was going smooth and I add all the static library ready then for linking here what I use:<br>
For CPU only:</p>
<pre><code class="lang-auto">        WHOLE_LIBRARIES
        torch;
        torch_cpu;

        LIBRARIES
        clog
        cpuinfo;
        libprotobuf;
        libprotoc;
        onnx_proto;
        onnx;
        c10;
        fbgemm;
        dnnl;
        foxi_loader;
        caffe2_protos;
        Caffe2_perfkernels_avx;
        Caffe2_perfkernels_avx2;
        Caffe2_perfkernels_avx512;
</code></pre>
<p>For GPU:</p>
<pre><code class="lang-auto">        WHOLE_LIBRARIES
        torch_cpu;
        torch_cuda;
        c10_cuda;

        LIBRARIES
        asmjit
        c10
        c10_cuda
        Caffe2_perfkernels_avx
        Caffe2_perfkernels_avx2
        Caffe2_perfkernels_avx512
        caffe2_protos
        clog
        cpuinfo_internals
        cpuinfo
        dnnl
        fbgemm
        foxi_loader
        mkldnn
        onnx_proto
        onnx
        libprotobuf
        libprotoc
        torch
</code></pre>
<h2>LIBRARIES</h2>
<p>TARGET_LINK_LIBRARIES(${__NAME}${_SUFFIX} INTERFACE ${LIBNAME})</p>
<h2>WHOLE_LIBRARIES</h2>
<p>TARGET_LINK_LIBRARIES(${__NAME}${_SUFFIX} INTERFACE -WHOLEARCHIVE:${LIBNAME})</p>

stakemura: <p>I appreciate your kindness.<br>
I will try your build options.<br>
Thanks!</p>

gemfield: <p>I have write a blog for pytorch static build: <a href="https://zhuanlan.zhihu.com/p/313481517" rel="noopener nofollow ugc">https://zhuanlan.zhihu.com/p/313481517</a>.<br>
For non-Chinese reader, I believe google translator will be helpful.</p>

Shisho_Sama: <p>Hi, Thanks, I followed your explanation and tried to build it on windows but I faced  these errors :</p>
<pre><code class="lang-auto">C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(6,1): error C2653: 'PThreadPool': is not a class
 or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,5): error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,19): error C3861: 'pthreadpool_create': identi
fier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,53): error C2065: 'pthreadpool_destroy': undec
lared identifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(7,74): error C2550: 'caffe2::PThreadPool': const
ructor initializer lists are only allowed on constructor definitions [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.
vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(9,8): error C2653: 'PThreadPool': is not a class
 or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(9,46): error C2270: 'get_thread_count': modifier
s not allowed on nonmember functions [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,8): error C2039: 'lock_guard': is not a membe
r of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,18): error C2065: 'lock_guard': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,24): error C2039: 'mutex': is not a member of
 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,29): error C2065: 'mutex': undeclared identif
ier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,31): error C2065: 'lock': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(10,36): error C2065: 'mutex_': undeclared identi
fier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(12,3): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(13,40): error C2065: 'threadpool_': undeclared i
dentifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(13,10): error C3861: 'pthreadpool_get_threads_co
unt': identifier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(16,6): error C2653: 'PThreadPool': is not a clas
s or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,8): error C2039: 'lock_guard': is not a membe
r of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,18): error C2065: 'lock_guard': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,24): error C2039: 'mutex': is not a member of
 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,29): error C2065: 'mutex': undeclared identif
ier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,31): error C2065: 'lock': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(17,36): error C2065: 'mutex_': undeclared identi
fier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(25,3): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(25,21): error C3861: 'pthreadpool_create': ident
ifier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(28,6): error C2653: 'PThreadPool': is not a clas
s or namespace name [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(29,16): error C2039: 'function': is not a member
 of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(29,24): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(29,24): error C2143: syntax error: missing ',' b
efore '&lt;' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,8): error C2039: 'lock_guard': is not a membe
r of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,18): error C2065: 'lock_guard': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,24): error C2039: 'mutex': is not a member of
 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,29): error C2065: 'mutex': undeclared identif
ier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,31): error C2065: 'lock': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(31,36): error C2065: 'mutex_': undeclared identi
fier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(33,3): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
  generated_unboxing_wrappers_2.cpp
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,16): error C2039: 'function': is not a member
 of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29333\include\vector(24): message :
see declaration of 'std' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,24): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,24): error C2143: syntax error: missing ';' b
efore '&lt;' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(36,42): error C2238: unexpected token(s) precedi
ng ';' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(38,7): error C2065: 'fn': undeclared identifier
[C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(42,7): error C2065: 'threadpool_': undeclared id
entifier [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(48,46): error C2039: 'fn': is not a member of 'c
affe2::run::Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(35): message : see declaration of 'caffe2::run::
Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(48,1): error C2039: '__this': is not a member of
 'caffe2::run::Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(35): message : see declaration of 'caffe2::run::
Context' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(51,7): error C2065: 'range': undeclared identifi
er [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(41,3): error C3861: 'pthreadpool_parallelize_1d'
: identifier not found [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,12): error C2143: syntax error: missing ';' b
efore '*' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,12): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,1): error C2365: 'caffe2::PThreadPool': redef
inition; previous definition was 'function' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(6): message : see declaration of 'caffe2::PThrea
dPool' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C2059: syntax error: '{' [C:\Users
\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C2143: syntax error: missing ';' b
efore '{' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(58,28): error C2447: '{': missing function heade
r (old-style formal list?) [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,27): error C4430: missing type specifier - in
t assumed. Note: C++ does not support default-int [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,15): error C2146: syntax error: missing ';' b
efore identifier 'pthreadpool_' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,30): error C2143: syntax error: missing ';' b
efore '{' [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
C:\Users\User\pytorch-1.7.0\caffe2\utils\threadpool\pthreadpool-cpp.cc(64,30): error C2447: '{': missing function heade
r (old-style formal list?) [C:\Users\User\pytorch-build-dir\caffe2\torch_cpu.vcxproj]
  VariableType_0.cpp
</code></pre>
<h2>Update1 :</h2>
<p>OK I manually excluded the <code>pthreadpool-cpp.cc</code> from torch_cpu project and everything seemingly build successfully and I have bunch of lib files.<br>
However upon linking I’m getting these errors :</p>
<pre><code class="lang-auto">Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2019	unresolved external symbol sswap_ referenced in function "void __cdecl THFloatBlas_swap(__int64,float *,__int64,float *,__int64)" (?THFloatBlas_swap@@YAX_JPEAM010@Z)	Detector_MTCNN_Test	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector_Test\torch_cpu.lib(THBlas.obj)	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp; __cdecl c10::operator&lt;&lt;(class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp;,struct c10::Half const &amp;)" (__imp_??6c10@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV12@AEBUHalf@0@@Z) referenced in function "public: void __cdecl &lt;lambda_4b127653adfae3530aa9273c394680d7&gt;::operator()(void)const " (??R&lt;lambda_4b127653adfae3530aa9273c394680d7&gt;@@QEBAXXZ)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::Scalar::Scalar(void)" (__imp_??0Scalar@c10@@QEAA@XZ) referenced in function "public: __cdecl torch::detail::TensorDataContainer::TensorDataContainer(class c10::ArrayRef&lt;__int64&gt;)" (??0TensorDataContainer@detail@torch@@QEAA@V?$ArrayRef@_J@c10@@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) protected: __cdecl c10::intrusive_ptr_target::intrusive_ptr_target(class c10::intrusive_ptr_target const &amp;)" (__imp_??0intrusive_ptr_target@c10@@IEAA@AEBV01@@Z) referenced in function "public: __cdecl c10::ivalue::Object::Object(struct c10::ivalue::Object const &amp;)" (??0Object@ivalue@c10@@QEAA@AEBU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) protected: class c10::intrusive_ptr_target &amp; __cdecl c10::intrusive_ptr_target::operator=(class c10::intrusive_ptr_target const &amp;)" (__imp_??4intrusive_ptr_target@c10@@IEAAAEAV01@AEBV01@@Z) referenced in function "public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &amp;)" (??4Object@ivalue@c10@@QEAAAEAU012@AEBU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl c10::TensorOptions::TensorOptions(class caffe2::TypeMeta)" (__imp_??0TensorOptions@c10@@QEAA@VTypeMeta@caffe2@@@Z) referenced in function "public: class at::Tensor __cdecl DetectorImpl::GetAffineTransformMatrix(class at::Tensor,class at::Tensor)" (?GetAffineTransformMatrix@DetectorImpl@@QEAA?AVTensor@at@@V23@0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor &amp; __cdecl at::Tensor::operator*=(class c10::Scalar)" (__imp_??XTensor@at@@QEAAAEAV01@VScalar@c10@@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor __cdecl at::Tensor::operator[](class at::Tensor)const " (__imp_??ATensor@at@@QEBA?AV01@V01@@Z) referenced in function "public: class at::Tensor __cdecl DetectorImpl::NMS(class at::Tensor,float,enum NMSMode)" (?NMS@DetectorImpl@@QEAA?AVTensor@at@@V23@MW4NMSMode@@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor __cdecl at::Tensor::index(class std::initializer_list&lt;struct at::indexing::TensorIndex&gt;)const " (__imp_?index@Tensor@at@@QEBA?AV12@V?$initializer_list@UTensorIndex@indexing@at@@@std@@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor &amp; __cdecl at::Tensor::index_put_(class std::initializer_list&lt;struct at::indexing::TensorIndex&gt;,class at::Tensor const &amp;)" (__imp_?index_put_@Tensor@at@@QEAAAEAV12@V?$initializer_list@UTensorIndex@indexing@at@@@std@@AEBV12@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: class at::Tensor &amp; __cdecl at::Tensor::index_put_(class std::initializer_list&lt;struct at::indexing::TensorIndex&gt;,class c10::Scalar)" (__imp_?index_put_@Tensor@at@@QEAAAEAV12@V?$initializer_list@UTensorIndex@indexing@at@@@std@@VScalar@c10@@@Z) referenced in function "public: class std::array&lt;class at::Tensor,10&gt; __cdecl DetectorImpl::CorrectBBoxes(class at::Tensor,float,float)" (?CorrectBBoxes@DetectorImpl@@QEAA?AV?$array@VTensor@at@@$09@std@@VTensor@at@@MM@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::Slice::Slice(class c10::optional&lt;__int64&gt;,class c10::optional&lt;__int64&gt;,class c10::optional&lt;__int64&gt;)" (__imp_??0Slice@indexing@at@@QEAA@V?$optional@_J@c10@@00@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(__int64)" (__imp_??0TensorIndex@indexing@at@@QEAA@_J@Z) referenced in function "public: class at::Tensor __cdecl DetectorImpl::NMS(class at::Tensor,float,enum NMSMode)" (?NMS@DetectorImpl@@QEAA?AVTensor@at@@V23@MW4NMSMode@@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(int)" (__imp_??0TensorIndex@indexing@at@@QEAA@H@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(struct at::indexing::Slice)" (__imp_??0TensorIndex@indexing@at@@QEAA@USlice@12@@Z) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::TensorIndex(class at::Tensor)" (__imp_??0TensorIndex@indexing@at@@QEAA@VTensor@2@@Z) referenced in function "public: class std::array&lt;class at::Tensor,10&gt; __cdecl DetectorImpl::CorrectBBoxes(class at::Tensor,float,float)" (?CorrectBBoxes@DetectorImpl@@QEAA?AV?$array@VTensor@at@@$09@std@@VTensor@at@@MM@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl at::indexing::TensorIndex::~TensorIndex(void)" (__imp_??1TensorIndex@indexing@at@@QEAA@XZ) referenced in function "public: __cdecl SimilarityTransform::SimilarityTransform(class at::Tensor,float,float,class at::Tensor)" (??0SimilarityTransform@@QEAA@VTensor@at@@MM0@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr &amp; __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr const &amp;)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@AEBU01@@Z) referenced in function "public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object const &amp;)" (??4Object@ivalue@c10@@QEAAAEAU012@AEBU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::StrongTypePtr &amp; __cdecl c10::StrongTypePtr::operator=(struct c10::StrongTypePtr &amp;&amp;)" (__imp_??4StrongTypePtr@c10@@QEAAAEAU01@$$QEAU01@@Z) referenced in function "public: struct c10::ivalue::Object &amp; __cdecl c10::ivalue::Object::operator=(struct c10::ivalue::Object &amp;&amp;)" (??4Object@ivalue@c10@@QEAAAEAU012@$$QEAU012@@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: struct c10::IValue __cdecl torch::jit::Module::forward(class std::vector&lt;struct c10::IValue,class std::allocator&lt;struct c10::IValue&gt; &gt;)" (__imp_?forward@Module@jit@torch@@QEAA?AUIValue@c10@@V?$vector@UIValue@c10@@V?$allocator@UIValue@c10@@@std@@@std@@@Z) referenced in function "public: struct std::pair&lt;class at::Tensor,class at::Tensor&gt; __cdecl DetectorImpl::DetectFaces(class cv::Mat &amp;,float,class std::array&lt;float,3&gt;,class std::array&lt;float,3&gt;)" (?DetectFaces@DetectorImpl@@QEAA?AU?$pair@VTensor@at@@V12@@std@@AEAVMat@cv@@MV?$array@M$02@3@1@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: void __cdecl torch::jit::Module::eval(void)" (__imp_?eval@Module@jit@torch@@QEAAXXZ) referenced in function "public: struct std::pair&lt;class at::Tensor,class at::Tensor&gt; __cdecl DetectorImpl::DetectFaces(class cv::Mat &amp;,float,class std::array&lt;float,3&gt;,class std::array&lt;float,3&gt;)" (?DetectFaces@DetectorImpl@@QEAA?AU?$pair@VTensor@at@@V12@@std@@AEAVMat@cv@@MV?$array@M$02@3@1@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\Detector.obj	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) bool __cdecl fbgemm::fbgemmSupportedCPU(void)" (__imp_?fbgemmSupportedCPU@fbgemm@@YA_NXZ) referenced in function "public: class std::vector&lt;enum c10::QEngine,class std::allocator&lt;enum c10::QEngine&gt; &gt; __cdecl &lt;lambda_fcc5437ea6fb470d27a4c81929ec1286&gt;::operator()(void)const " (??R&lt;lambda_fcc5437ea6fb470d27a4c81929ec1286&gt;@@QEBA?AV?$vector@W4QEngine@c10@@V?$allocator@W4QEngine@c10@@@std@@@std@@XZ)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\torch_cpu.lib(Context.cpp.obj)	1	
Error	LNK2019	unresolved external symbol "__declspec(dllimport) void __cdecl fbgemm::Quantize&lt;signed char,0&gt;(float const *,signed char *,int,struct fbgemm::TensorQuantizationParams const &amp;,int,int)" (__imp_??$Quantize@C$0A@@fbgemm@@YAXPEBMPEACHAEBUTensorQuantizationParams@0@HH@Z) referenced in function "void __cdecl at::native::quantize_vec&lt;struct c10::qint8,8&gt;(double,__int64,float const *,struct c10::qint8 *,unsigned __int64)" (??$quantize_vec@Uqint8@c10@@$07@native@at@@YAXN_JPEBMPEAUqint8@c10@@_K@Z)	Detector	D:\Codes\fac_ver\cpp\port\LibtorchPort\Detector\torch_cpu.lib(affine_quantizer.obj)	1	

</code></pre>
<p>Heres the full linker errors : <a href="https://paste.ee/p/AFZ1l" rel="noopener nofollow ugc">https://paste.ee/p/AFZ1l</a><br>
and this is the VS output : <a href="https://paste.ee/p/uF8Jz" rel="noopener nofollow ugc">https://paste.ee/p/uF8Jz</a><br>
which shows linker warnings such as :</p>
<pre><code class="lang-auto">1&gt;   Creating library D:\Codes\fac_ver\cpp\port\LibtorchPort\x64\Debug\Test_dummy.lib and object D:\Codes\fac_ver\cpp\port\LibtorchPort\x64\Debug\Test_dummy.exp
1&gt;LINK : warning LNK4217: symbol '??0Error@c10@@QEAA@USourceLocation@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z (public: __cdecl c10::Error::Error(struct c10::SourceLocation,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;))' defined in 'c10.lib(Logging.obj)' is imported by 'Test_dummy.obj' in function '"public: __cdecl torch::detail::TensorDataContainer::TensorDataContainer(class std::initializer_list&lt;struct torch::detail::TensorDataContainer&gt;)" (??0TensorDataContainer@detail@torch@@QEAA@V?$initializer_list@UTensorDataContainer@detail@torch@@@std@@@Z)'
1&gt;LINK : warning LNK4217: symbol '?msg@Error@c10@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ (public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; const &amp; __cdecl c10::Error::msg(void)const )' defined in 'c10.lib(Logging.obj)' is imported by 'Test_dummy.obj' in function '__catch$?ToTensor@@YA?AVTensor@at@@AEBVMat@cv@@AEB_N1AEBH@Z$0'
</code></pre>
<p>What should I do?</p>
<p>I’m building 1.7.0 as well (cpu only)<br>
I’d greatly appreciate any kind of help in this.</p>

mheriyanto: <p>Are there any updates for this issue?</p>