CMake error and fatal error LNK1181 building from source on Windows 10

I’m getting the following error while compiling PyTorch from source:

[1818/2610] Linking CXX shared library bin\caffe2.dll
FAILED: bin/caffe2.dll lib/caffe2.lib
cmd.exe /C "cd . && "C:\Program Files (x86)\CMake\bin\cmake.exe" -E vs_link_dll --intdir=caffe2\CMakeFiles\caffe2.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MIB055~1\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\link.exe /nologo @CMakeFiles\caffe2.rsp  /out:bin\caffe2.dll /implib:lib\caffe2.lib /pdb:bin\caffe2.pdb /dll /version:0.0 /INCREMENTAL:NO   && cd ."
LINK: command "C:\PROGRA~2\MIB055~1\2017\COMMUN~1\VC\Tools\MSVC\1411~1.255\bin\HostX64\x64\link.exe /nologo @CMakeFiles\caffe2.rsp /out:bin\caffe2.dll /implib:lib\caffe2.lib /pdb:bin\caffe2.pdb /dll /version:0.0 /INCREMENTAL:NO /MANIFEST /MANIFESTFILE:bin\caffe2.dll.manifest" failed (exit code 1181) with the following output:
LINK : fatal error LNK1181: cannot open input file 'Files/pytorch/build/lib/caffe2_protos.lib'
ninja: build stopped: subcommand failed.

Full-log:
ninja_build_full-log

This happened when I followed this solution:
pytorch_discussion

Previously I have tried to install it from source using VS as mentioned in the README, but I encountered a CMake error:

CMake Error at caffe2_gpu_generated_THCTensor.cu.obj.Release.cmake:219

And now when I tried to use the same process I get the following error:

-- Build files have been written to: C:/Program Files/pytorch/build
ninja: error: unknown target '/maxcpucount:8'

Full-log:
VS_full-log

Could you please help me with this issue?

My setup:

OS: Microsoft Windows 10
CMake version: 3.14.5
Python 3.6.1 :: Anaconda custom (64-bit)
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130
cuDNN version: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\cudnn64_7.dl
My env-var PATH:

@peterjc123 could you please help me with this?

Hey, would you please get a fresh clone and do that again? Looks like you configured with Ninja at first and turned it off later.

BTW, could you please send me the ninja.build file in the build directory?

Well, I saw that your build directory contains space. As a workground, you can just avoid that to make build pass. However, more details to fix this issue are welcomed.

1 Like

Thank you for your quick response.
I changed the build directory and tried again. However another error appears:

C:\pytorch\torch/csrc/jit/tracer.h(314): warning C4273: 'torch::jit::tracer::addInputs': inconsistent dll linkage [C:\p
ytorch\build\caffe2\torch\torch_python.vcxproj]
  C:\pytorch\torch/csrc/jit/tracer.h(299): note: see previous definition of 'addInputs'
C:\pytorch\torch/csrc/jit/tracer.h(321): warning C4273: 'torch::jit::tracer::addInputs': inconsistent dll linkage [C:\p
ytorch\build\caffe2\torch\torch_python.vcxproj]
  C:\pytorch\torch/csrc/jit/tracer.h(305): note: see previous definition of 'addInputs'
  serialization.cpp
C:\pytorch\torch/csrc/jit/tracer.h(314): warning C4273: 'torch::jit::tracer::addInputs': inconsistent dll linkage [C:\p
ytorch\build\caffe2\torch\torch_python.vcxproj]
  C:\pytorch\torch/csrc/jit/tracer.h(299): note: see previous definition of 'addInputs'
C:\pytorch\torch/csrc/jit/tracer.h(321): warning C4273: 'torch::jit::tracer::addInputs': inconsistent dll linkage [C:\p
ytorch\build\caffe2\torch\torch_python.vcxproj]
  C:\pytorch\torch/csrc/jit/tracer.h(305): note: see previous definition of 'addInputs'
     Creating library C:/pytorch/build/lib/Release/torch_python.lib and object C:/pytorch/build/lib/Release/torch_pytho
  n.exp
init.cpp.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobject THPDeviceTy
pe) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_arg_parser.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobject TH
PDeviceType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
tensor_new.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobject THPDevice
Type) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
Event.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobject THPDeviceType)
 imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobject THPDeviceTy
pe) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_variable_methods.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobj
ect THPDeviceType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_torch_functions.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobje
ct THPDeviceType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_nn_functions.obj : warning LNK4049: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobject
THPDeviceType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_sugared_value.obj : warning LNK4217: locally defined symbol ?THPDeviceType@@3U_typeobject@@A (struct _typeobject
 THPDeviceType) imported in function "void __cdecl torch::jit::script::`dynamic initializer for 'empty_trees''(void)" (
??__Eempty_trees@script@jit@torch@@YAXXZ) [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4049: locally defined symbol ?THPDtypeType@@3U_typeobject@@A (struct _typeobject THPDtypeType
) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_variable_methods.obj : warning LNK4049: locally defined symbol ?THPDtypeType@@3U_typeobject@@A (struct _typeobje
ct THPDtypeType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_sugared_value.obj : warning LNK4049: locally defined symbol ?THPDtypeType@@3U_typeobject@@A (struct _typeobject
THPDtypeType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_tensor.obj : warning LNK4049: locally defined symbol ?THPDtypeType@@3U_typeobject@@A (struct _typeobject THPDtyp
eType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_arg_parser.obj : warning LNK4049: locally defined symbol ?THPDtypeType@@3U_typeobject@@A (struct _typeobject THP
DtypeType) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::TypeErro
r::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
Module.cpp.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::TypeEr
ror::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
tensor_apply.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::Type
Error::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
tensor_new.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::TypeEr
ror::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
tensor_numpy.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::Type
Error::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::TypeErro
r::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_variable.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::T
ypeError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_variable_indexing.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl
 torch::TypeError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_tensor.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::Typ
eError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_arg_parser.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch:
:TypeError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
DynamicTypes.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::Type
Error::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
Generator.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::TypeErr
or::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_function.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::T
ypeError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_legacy_variable.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl t
orch::TypeError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_variable_methods.obj : warning LNK4217: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl
torch::TypeError::TypeError(char const *,...)) imported in function "struct _object * __cdecl torch::autograd::THPVaria
ble_type(struct _object *,struct _object *,struct _object *)" (?THPVariable_type@autograd@torch@@YAPEAU_object@@PEAU3@0
0@Z) [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_torch_functions.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl t
orch::TypeError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
python_nn_functions.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torc
h::TypeError::TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
Device.obj : warning LNK4049: locally defined symbol ??0TypeError@torch@@QEAA@PEBDZZ (public: __cdecl torch::TypeError:
:TypeError(char const *,...)) imported [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4217: locally defined symbol ?ToONNX@jit@torch@@YA?AV?$shared_ptr@UGraph@jit@torch@@@std@@AEA
V34@W4OperatorExportTypes@onnx@2@@Z (class std::shared_ptr<struct torch::jit::Graph> __cdecl torch::jit::ToONNX(class s
td::shared_ptr<struct torch::jit::Graph> &,enum torch::onnx::OperatorExportTypes)) imported in function "void __cdecl t
orch::jit::initJITBindings(struct _object *)" (?initJITBindings@jit@torch@@YAXPEAU_object@@@Z) [C:\pytorch\build\caffe2
\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4217: locally defined symbol ?BlockToONNX@jit@torch@@YAXPEAUBlock@12@0W4OperatorExportTypes@o
nnx@2@V?$unordered_map@PEAUValue@jit@torch@@PEAU123@U?$hash@PEAUValue@jit@torch@@@std@@U?$equal_to@PEAUValue@jit@torch@
@@5@V?$allocator@U?$pair@QEAUValue@jit@torch@@PEAU123@@std@@@5@@std@@@Z (void __cdecl torch::jit::BlockToONNX(struct to
rch::jit::Block *,struct torch::jit::Block *,enum torch::onnx::OperatorExportTypes,class std::unordered_map<struct torc
h::jit::Value *,struct torch::jit::Value *,struct std::hash<struct torch::jit::Value *>,struct std::equal_to<struct tor
ch::jit::Value *>,class std::allocator<struct std::pair<struct torch::jit::Value * const,struct torch::jit::Value *> >
>)) imported in function "void __cdecl torch::jit::initJITBindings(struct _object *)" (?initJITBindings@jit@torch@@YAXP
EAU_object@@@Z) [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4217: locally defined symbol ?PrepareDivisionForONNX@jit@torch@@YAXAEBV?$shared_ptr@UGraph@ji
t@torch@@@std@@@Z (void __cdecl torch::jit::PrepareDivisionForONNX(class std::shared_ptr<struct torch::jit::Graph> cons
t &)) imported in function "void __cdecl torch::jit::initJITBindings(struct _object *)" (?initJITBindings@jit@torch@@YA
XPEAU_object@@@Z) [C:\pytorch\build\caffe2\torch\torch_python.vcxproj]
init.cpp.obj : warning LNK4217: locally defined symbol ?getRecursiveScriptMode@script@jit@torch@@YAAEA_NXZ (bool & __cd
ecl torch::jit::script::getRecursiveScriptMode(void)) imported in function "private: static class pybind11::handle __cd
ecl <lambda_699ff1579e5ea22a9941363e0bb1e852>::<lambda_invoker_cdecl>(struct pybind11::detail::function_call &)" (?<lam
bda_invoker_cdecl>@<lambda_699ff1579e5ea22a9941363e0bb1e852>@@CA?AVhandle@pybind11@@AEAUfunction_call@detail@3@@Z) [C:\
pytorch\build\caffe2\torch\torch_python.vcxproj]
  torch_python.vcxproj -> C:\pytorch\build\bin\Release\torch_python.dll
Traceback (most recent call last):
  File "setup.py", line 752, in <module>
    build_deps()
  File "setup.py", line 320, in build_deps
    build_dir='build')
  File "C:\pytorch\tools\build_pytorch_libs.py", line 88, in build_caffe2
    check_call(build_cmd, cwd=build_dir, env=my_env)
  File "C:\Users\gjben\Anaconda3\lib\subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '/maxcpucount:8']' returned non-zero exit status 1.

It happens when running:

python setup.py build --cmake

I couldn’t find any error in your post.

Here you have it:

Traceback (most recent call last):
  File "setup.py", line 752, in <module>
    build_deps()
  File "setup.py", line 320, in build_deps
    build_dir='build')
  File "C:\pytorch\tools\build_pytorch_libs.py", line 88, in build_caffe2
    check_call(build_cmd, cwd=build_dir, env=my_env)
  File "C:\Users\gjben\Anaconda3\lib\subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '/maxcpucount:8']' returned non-zero exit status 1.

And here you have the lines I could record from the full-log:
partial-log

Btw, this time I used:

set CMAKE_GENERATOR=Visual Studio 15 2017

Therefore I couln’t find any file

Would you please use Ninja as the generator? I didn’t find any relevant clues in your log that may cause the build failure. Actually, I’m also facing some really weird issues when using MSBuild and CMake 3.14.

Sure, I will let you know the results as soon as I success or get something weird.

Once more, thank you for your help.

Thank you very much for your help.
It worked. In resume:

  • I changed the build directory to ‘C:\pytorch’ (no spaces in it)
  • I used ninja as the generator following:
    Install with ninja

Just as reference this is my env info:

PyTorch version: 1.2.0a0+f2623c7
Is debug build: No
CUDA used to build PyTorch: 10.0

OS: Microsoft Windows 10 Home
GCC version: (tdm64-1) 5.1.0
CMake version: version 3.14.5

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 10.0.130
GPU models and configuration: GPU 0: GeForce GTX 1070
Nvidia driver version: 425.25
cuDNN version: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\cudnn64_7.dll

Versions of relevant libraries:
[pip] numpy==1.12.1
[pip] numpydoc==0.6.0
[pip] torch==1.2.0a0+f2623c7
[conda] mkl                       2019.0                    <pip>
[conda] mkl                       2017.0.1                      0
[conda] mkl-include               2019.0                    <pip>
[conda] mkl-service               1.1.2                    py36_3
[conda] torch                     1.2.0a0+f2623c7           <pip>