# ERROR LNK2019 unresolved external symbol ""float __cdecl pow(float,int)" in function ""void __cdecl test_atomic_mul<float>(void)"

Hi everyone!

I have been trying to install Pytorch for over a week now, and I can not get it to work. After approximately 8 hours, the build always stops with:

Making of project "C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\caffe2\xla_tensor_test.vcxproj" is finished (Standardziele).

Error in build process.


Then I get a bunch of similar warnings like:

"C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\install.vcxproj" (Standardziel) (1) ->
(ClCompile Ziel) ->
cl : Command line warning D9025 : overriding “/W1” with “/w” [C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\third_party\protobuf\cmake\libprotobuf.vcxproj]


And finally:

"C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\install.vcxproj" (Standardziel) (1) ->
cuda_atomic_ops_test_generated_cuda_atomic_ops_test.cu.obj : error LNK2019: unresolved external symbol ""float __cdecl pow(float,int)" (?pow@@YAMMH@Z)" in function ""void __cdecl test_atomic_mul<float>(void)" (?
?$test_atomic_mul@M@@YAXXZ)". [C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\caffe2\cuda_atomic_ops_test.vcxp roj] cuda_atomic_ops_test_generated_cuda_atomic_ops_test.cu.obj : error LNK2019: unresolved external symbol ""double __cdecl pow(double,int)" (?pow@@YANNH@Z)" in function ""void __cdecl test_atomic_mul<double>(void)" (??$test_atomic_mul@N@@YAXXZ)". [C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\caffe2\cuda_atomic_ops_test.v
cxproj]

473 Warnings
3 Errors

Passed Time 08:08:32.28
Traceback (most recent call last):
build_deps()
build_caffe2(version=version,
cmake.build(my_env)
self.run(build_args, my_env)
check_call(command, cwd=self.build_dir, env=env)
File "C:\Users\gooog\anaconda3\envs\torchbuild\lib\subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '/p:CL_MPCount=1']' returned non-zero exit status 1.


I translated some german parts, so don’t be confused if something sounds off. I did not know, how (Standartziel) is called in english, but it basically means “default target”. I hope, everything else is understandable.
Some general information on my setup:

• Windows 10 (64 bit)
• GPU: Nvidia GeForce 920M (Computing Capability = 3.5)
• Driver Version: 426.00 (latest)
• Visual Studio 2019 16.9.4 (Community)
• CUDA 10.1.243
• CuDNN 8.0.5

This is how I install:

cd C:\Users\gooog\Downloads
mkdir Pytorch
cd Pytorch
conda create --name torchbuild
y
conda activate torchbuild
conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses
y
conda install -c conda-forge libuv=1.39
y
git clone --branch v1.7.0 https://github.com/pytorch/pytorch.git pytorch-1.7.0
cd pytorch-1.7.0
git clean -xdfcond
python setup.py clean
git submodule deinit -f --all
git submodule sync --recursive
git submodule update --init --recursive


At this point, I manually change two things in the source code in order to fix some bugs I encountered earlier:

1. Adding const to C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\aten\src\ATen\native\CompositeRandomAccessorCommon.h according to:
Visual Studio Feedback

\pytorch-1.7.0\cmake\public\cuda.cmake according to:
[test] alternative fix for vc 16.8 with nvcc by peterjc123 · Pull Request #54391 · pytorch/pytorch · GitHub

Then I continue installing:

set TMP_DIR_WIN=C:\Users\gooog\Downloads
set USE_NINJA=OFF
set CMAKE_VERBOSE_MAKEFILE=1
set CMAKE_GENERATOR=Visual Studio 16 2019
set CMAKE_GENERATOR_TOOLSET_VERSION=14.28
set DISTUTILS_USE_SDK=1
set PATH=%TMP_DIR_WIN%\bin;%PATH%
sccache --stop-server
sccache --start-server
sccache --zero-stats
set CC=sccache-cl
set CXX=sccache-cl
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%
set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe
set MAX_JOBS=1
python setup.py build --cmake
python setup.py install


Use_mkl.bat and Use_sccache.bat were copied from pytorch/.jenkins/pytorch/win-test-helpers/installation-helpers at master · pytorch/pytorch · GitHub

Since the files were rather long, I uploaded:

This is the first time I try to install something from source, so please excuse some (probably) strange steps, like manually changing the source files .
I need pytorch for my thesis, so any help would be very very much appreciated. Also let me know, if you need anything else.

Based on the provided log it seems the error is:

unresolved external symbol ""float __cdecl pow(float,int)"


which points towards this older issue, which should have been already solved in newer PyTorch versions.
In case you need to use PyTorch 1.7.0 you could apply the proposed fixes mentioned in the issue or you could alternatively just update to the latest stable or nightly release.

1 Like

Since my GPU is only compatible with CUDA 10.1, I think I am restricted to Pytorch v1.7.0 according to this table: pytorch/CONTRIBUTING.md at master · pytorch/pytorch · GitHub
I did not fully understand, how exactly CUDA and Pytorch versions depend on each other, so if you think that a newer version might also work, please let me know.
Unfortunately, I was not able to find the older issue (were the square brackets supposed to be a link?).
I found a bunch of other link errors, but none of them seemed to fit my problem.
Could you maybe provide a link to the issue you meant?

I’m not sure why this would be the case.
CUDA10.0 - CUDA11.3 all support GPUs with compute capability 3.5, so you could use all these CUDA toolkits.

Sorry for the wrong link, as apparently I didn’t post the right URL. Will edit the previous post and add the right link here as well.

1 Like

Thanks again for the help.

As far as I understood, CUDA v10.2 and higher require a graphics driver version >= 441.22, as mentioned in the second table here, but the newest version I could find for my GPU is 426 (nvidia offers 425.31 here, but somehow CUDA 10.1 included version 426.00).

Once again, if this has to be seen as a recommendation more than a hard requirement, or if there is another way of getting newer driver versions, please let me know .

I added a third manual fix according to this solution mentioned in your link and will now try again.
Thanks again for your help, I will let you know if it worked.

I think the fix worked so far, as the build goes further than before. Unfortunately, I encountered another error for which I could not find a fix:

Copying extension caffe2.python.caffe2_pybind11_state_gpu
building 'torch._C' extension
creating build\temp.win-amd64-3.9
creating build\temp.win-amd64-3.9\Release
creating build\temp.win-amd64-3.9\Release\torch
creating build\temp.win-amd64-3.9\Release\torch\csrc
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\gooog\anaconda3\envs\torchbase\include -IC:\Users\gooog\anaconda3\envs\torchbase\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\ATLMFC\include -IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt -IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt /Tctorch/csrc/stub.c /Fobuild\temp.win-amd64-3.9\Release\torch/csrc/stub.obj /MD /EHsc /DNOMINMAX /wd4267 /wd4251 /wd4522 /wd4522 /wd4838 /wd4305 /wd4244 /wd4190 /wd4101 /wd4996 /wd4275
stub.c
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\torch\lib /LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/lib/x64 /LIBPATH:C:\Users\gooog\anaconda3\envs\torchbase\libs /LIBPATH:C:\Users\gooog\anaconda3\envs\torchbase\PCbuild\amd64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\ATLMFC\lib\x64 /LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\lib\x64 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64 /LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64 /LIBPATH:C:\Users\gooog\Downloads\mkl\lib torch_python.lib /EXPORT:PyInit__C build\temp.win-amd64-3.9\Release\torch/csrc/stub.obj /OUT:build\lib.win-amd64-3.9\torch\_C.cp39-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.9\Release\torch/csrc\_C.cp39-win_amd64.lib /NODEFAULTLIB:LIBCMT.LIB
LINK : fatal error LNK1181: Input file ".obj" cannot be opened.
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29910\\bin\\HostX64\\x64\\link.exe' failed with exit code 1181


I was not able to identify the relevant lines in the logs, so I send all 3:

I would be really thankful if you could help me again, since I do not know what to try anymore.

I’m unfortunately not deeply familiar with laptop GPUs, so don’t know much about the driver support.

The current log error seems to be a bit vague in only mentioning that an “.obj” file cannot be opened. Note that the other two cmake files seem to be blocked.

1 Like

Thank your for the ongoing support.
I corrected the links and the CMake files should be available now.

I think the (freely translated) relevant error message is:

C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\CMakeFiles\CMakeTmp\src.cxx(1,10): fatal error C1083: cannot open file (Include): "glog/stl_logging.h": No such file or directory [C:\Users\gooog\Downloads\Pytorch\pytorch-1.7.0\build\CMakeFiles\CMakeTmp\cmTC_e63a9.vcxproj]


Which lead to this issue. I checked my CMakeLists.txt, but all these changes were already included. Any idea, what might be the problem?

Could you disable the GLOG usage via USE_GLOG=0 in your env?
Besides that it also seems that your current setup is missing pthread.h, mpi.h, cpuid.h, and execinfo.h.
While these errors are raised as fatal error, I’m unsure if these would really break the build or skip the usage of some libs.

Did you make sure to use the recommended Visual Studio version as described here?

Thank you for the suggestion!

I reinstalled Visual Studio using this file (which installs BuildTools), and will set USE_GLOG=0, once it is done.
While reinstalling CUDA, I now get the message that the installer can not find a supported version of Visual Studio, even though I located and added the following directories to my PATH:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\amd64 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\bin\Hostx64\x64
As far as I understood, CUDA wants a “real” Visual Studio version, e.g. Community, but the install instructions clearly suggest the BuildTools. Any idea on how to solve this?

Do you think it might help to install the missing files you mentioned? Where are they normally delivered?

I’m unfortunately not familiar with the Windows setup and don’t know which Visual Studio version etc. is needed, so we would have to wait for a Windows expert such as @peterjc123.

Okay, nonetheless thank you very much for your help so far.
Hopefully @peterjc123 can help me resolve the last issues .

No no no, don’t add those paths to PATH systemwide. Actually, there should be a shortcut called x64 Native Tools Command Prompt for VS 2019 if you use “Windows Search”. Opening that window, all the VS related environmental variables will be properly set.

As far as I understood, CUDA wants a “real” Visual Studio version, e.g. Community, but the install instructions clearly suggest the BuildTools. Any idea on how to solve this?

It doesn’t care if you have build tools or community. Nvcc would be happy if you have MSVC toolchain installed.

As for your problem in building the library, it looks pretty similar to Cannot build PyTorch with Python 3.9 on Windows · Issue #47460 · pytorch/pytorch (github.com) and is resolved by Fix python 3.9 builds on Windows by peterjc123 · Pull Request #47602 · pytorch/pytorch (github.com).

1 Like

Thanks for helping out.

I deleted the two lines from my PATH, and will use the VS command prompt you suggested. Does that mean, I should remove the following commands from my installation routine?


set CMAKE_GENERATOR=Visual Studio 16 2019

set CMAKE_GENERATOR_TOOLSET_VERSION=14.28

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%

set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.exe


Another question:
The issue that CUDA cannot find Visual Studio remains, even though I have

MSVC v142 - VS 2019 C++-x64/x86-Buildtools (v14.28)

installed (I installed Visual Studio and all components using this previously mentioned file)
Should I just reinstall it using VS Community (which seemed to work), and install the newest MSVC and SDK?
And if so, would you suggest VS Community 16.8.5 - matching the current Buildtools version - or the latest?

If you want to build with the VS generator, then you should probably set CMAKE_GENERATOR, otherwise, the Ninja generator will be used and you don’t need to set any one of them.

[quote=“PlsHelp, post:14, topic:121318”]
The issue that CUDA cannot find Visual Studio remains, even though I have

MSVC v142 - VS 2019 C+±x64/x86-Buildtools (v14.28)

installed (I installed Visual Studio and all components using this previously mentioned file)
Should I just reinstall it using VS Community (which seemed to work), and install the newest MSVC and SDK?

If it could work, then maybe you could just reinstall that. Actually, I don’t know too much about your local environment.

And if so, would you suggest VS Community 16.8.5 - matching the current Buildtools version - or the latest?

I see that you are using my patch. So it won’t have any problem using the latest one.

I do not remember exactly what happened, but I build with the VS generator, since Ninja had some issues for me.

I reinstalled the latest Visual Studio Community and tried to build using the fix you provided in your first reply. However, after approximately 3 hours, the build errors out again. I think these are the relevant error messages in CMakeError.log:



Source file was:
#include <stdint.h>
static inline void cpuid(uint32_t *eax, uint32_t *ebx,
uint32_t *ecx, uint32_t *edx)
{
uint32_t a = *eax, b, c = *ecx, d;
asm volatile ( "cpuid" : "+a"(a), "=b"(b), "+c"(c), "=d"(d) );
*eax = a; *ebx = b; *ecx = c; *edx = d;
}
int main() {
uint32_t a,b,c,d;
cpuid(&a, &b, &c, &d);
return 0;
}


Based on the command prompt output, the problem seems to be related to gloo:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(
...

>
(CustomBuild Ziel) ->
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.target


I do not understand what gloo does, but could it help to just set USE_GLOO=0, and would this in any way affect the build?

On another note, I am still missing the following files (as ptrblck already pointed out):

• glog/stl_logging.h
• mpi.h
• cpuid.h
• execinfo.h

Would you confirm that this is not problematic for the build / later use?

Conserning the first issue, I tried to build again with USE_GLOO=0, but I am hitting the same error. Based on this somewhat smiliar issue, I think it should say __asm__ insted of asm in \build\CMakeFiles\CMakeTmp\src.c, but since this is a temporary file, that is generated only during the build, I do not know how to fix this. Any idea on what to do @peterjc123 ?

Could you please share me the full log? BTW, would you please share the log if you use the Ninja generator?

These are the logs of the last run (with USE_GLOO=0)

I will now try to build with Ninja again and send you the logs once it is done. In order to do so, I just set USE_NINJA=ON and remove the following lines from my installation routine, right?

set CMAKE_VERBOSE_MAKEFILE=1
set CMAKE_GENERATOR=Visual Studio 16 2019
set CMAKE_GENERATOR_TOOLSET_VERSION=14.29
set DISTUTILS_USE_SDK=1
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%
set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64\cl.exe


So my new installation routine will be the following:



set USE_NINJA=ON
set PATH=%TMP_DIR_WIN%\bin;%PATH%
sccache --stop-server
sccache --start-server
sccache --zero-stats
set CC=sccache-cl
set CXX=sccache-cl
set MAX_JOBS=1
set USE_GLOG=0
set USE_GLOO=0
python setup.py build --cmake
python setup.py install


Thanks a lot for your help!

The logs you provided are not informative. By “full log”, I mean you redirect stdout and stderr to a log file (by appending > build.log 2>&1 after every command or just write all the commands into a script and run that script with this pattern) and please upload that log file.

I will now try to build with Ninja again and send you the logs once it is done. In order to do so, I just set USE_NINJA=ON and remove the following lines from my installation routine, right?

You still need this if you use a regular CMD window instead of opening a x64 MSVC dev shell.
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%

BTW, set DISTUTILS_USE_SDK=1 is still needed.