Setting Up PyTorch with CUDA from Source in Mingw x86_64

ngminteck: <p>I am a postgraduate student in AI, and I wish to use GIMP <a href="https://www.gimp.org/news/2025/02/10/gimp-3-0-RC3-released/" rel="noopener nofollow ugc">GIMP 3.0 RC3 Released - GIMP</a> , an open-source tool like Photoshop, as an interface to demo my school project feature about AI photo editing like segmentation, AI generation inpainting and etc.</p>
<p>I’m facing trouble building the source code of PyTorch. The reason I’m building PyTorch from source is that GIMP 3.0 RC3 uses MSYS2 Mingw x86_64 Python, and in that environment, it is restricted from calling pip install."</p>
<p>Below is the setup error, "Any help or tips would be appreciated</p>
<pre><code class="lang-auto">ng_mi@ClarenceNg MINGW64 /c/Users/ng_mi/Nus/ITSS/pytorch
# python setup.py bdist_wheel
Building wheel torch-2.7.0a0+git69301fb
-- Building version 2.7.0a0+git69301fb
cmake -GNinja -DBUILD_CAFFE2_OPS=1 -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja -DCMAKE_INSTALL_PREFIX=C:/Users/ng_mi/Nus/ITSS/pytorch/torch -DCMAKE_PREFIX_PATH=C:/msys64/mingw64/lib/python3.12/site-packages -DCMAKE_SYSTEM_PROCESSOR=x86_64 -DPython_EXECUTABLE=C:/msys64/mingw64/bin/python.exe -DTORCH_BUILD_VERSION=2.7.0a0+git69301fb -DUSE_CUDA=1 -DUSE_DISTRIBUTED=0 -DUSE_FBGEMM=0 -DUSE_MKL=0 -DUSE_MKLDNN=1 -DUSE_NUMPY=True -DUSE_OPENMP=1 -DUSE_ROCM=1 C:/Users/ng_mi/Nus/ITSS/pytorch
CMake Warning at CMakeLists.txt:422 (message):
  TensorPipe cannot be used on Windows.  Set it to OFF


CMake Warning at CMakeLists.txt:424 (message):
  KleidiAI cannot be used on Windows.  Set it to OFF


-- Current compiler supports avx2 extension. Will build perfkernels.
-- Current compiler supports avx512f extension. Will build fbgemm.
-- Could not find hardware support for NEON on this machine.
-- No OMAP3 processor on this machine.
-- No OMAP4 processor on this machine.
-- Compiler does not support SVE extension. Will not build perfkernels.
-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6 (found version "12.6")
-- The CUDA compiler identification is NVIDIA 12.6.20 with host compiler MSVC 19.42.34436.0
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - failed
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe - broken
CMake Error at C:/msys64/mingw64/share/cmake/Modules/CMakeTestCUDACompiler.cmake:59 (message):
  The CUDA compiler

    "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'C:/Users/ng_mi/Nus/ITSS/pytorch/build/CMakeFiles/CMakeScratch/TryCompile-nhouhq'

    Run Build Command(s): C:/msys64/mingw64/bin/ninja.exe -v cmTC_3ef1b
    [1/2] C:\PROGRA~1\NVIDIA~2\CUDA\v12.6\bin\nvcc.exe -forward-unknown-to-host-compiler   -DLIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_OPERATIONS -Xfatbin -compress-all  -Xcompiler=" -Zi -Ob0 -Od /RTC1" "--generate-code=arch=compute_52,code=[compute_52,sm_52]" -Xcompiler=-MDd -MD -MT CMakeFiles\cmTC_3ef1b.dir\main.cu.obj -MF CMakeFiles\cmTC_3ef1b.dir\main.cu.obj.d -x cu -c C:\Users\ng_mi\Nus\ITSS\pytorch\build\CMakeFiles\CMakeScratch\TryCompile-nhouhq\main.cu -o CMakeFiles\cmTC_3ef1b.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_3ef1b.dir\,-FS
    main.cu
    tmpxft_0000578c_00000000-10_main.cudafe1.cpp
    [2/2] C:\WINDOWS\system32\cmd.exe /C "cd . &amp;&amp; C:\msys64\mingw64\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_3ef1b.dir --rc=C:\msys64\mingw64\bin\windres.exe --mt="" --manifests  -- C:\msys64\mingw64\bin\ld.exe /nologo CMakeFiles\cmTC_3ef1b.dir\main.cu.obj  /out:cmTC_3ef1b.exe /implib:cmTC_3ef1b.lib /pdb:cmTC_3ef1b.pdb /version:0.0 /debug /INCREMENTAL  cudadevrt.lib  cudart_static.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -LIBPATH:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/lib/x64" &amp;&amp; cd ."
    FAILED: cmTC_3ef1b.exe
    C:\WINDOWS\system32\cmd.exe /C "cd . &amp;&amp; C:\msys64\mingw64\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_3ef1b.dir --rc=C:\msys64\mingw64\bin\windres.exe --mt="" --manifests  -- C:\msys64\mingw64\bin\ld.exe /nologo CMakeFiles\cmTC_3ef1b.dir\main.cu.obj  /out:cmTC_3ef1b.exe /implib:cmTC_3ef1b.lib /pdb:cmTC_3ef1b.pdb /version:0.0 /debug /INCREMENTAL  cudadevrt.lib  cudart_static.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -LIBPATH:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/lib/x64" &amp;&amp; cd ."
    RC Pass 1: command "C:\msys64\mingw64\bin\windres.exe /fo CMakeFiles\cmTC_3ef1b.dir/manifest.res CMakeFiles\cmTC_3ef1b.dir/manifest.rc" failed (exit code 1) with the following output:
    Usage: C:\msys64\mingw64\bin\windres.exe [option(s)] [input-file] [output-file]
     The options are:
      -i --input=&lt;file&gt;            Name input file
      -o --output=&lt;file&gt;           Name output file
      -J --input-format=&lt;format&gt;   Specify input format
      -O --output-format=&lt;format&gt;  Specify output format
      -F --target=&lt;target&gt;         Specify COFF target
         --preprocessor=&lt;program&gt;  Program to use to preprocess rc file
         --preprocessor-arg=&lt;arg&gt;  Additional preprocessor argument
      -I --include-dir=&lt;dir&gt;       Include directory when preprocessing rc file
      -D --define &lt;sym&gt;[=&lt;val&gt;]    Define SYM when preprocessing rc file
      -U --undefine &lt;sym&gt;          Undefine SYM when preprocessing rc file
      -v --verbose                 Verbose - tells you what it's doing
      -c --codepage=&lt;codepage&gt;     Specify default codepage
      -l --language=&lt;val&gt;          Set language when reading rc file
         --use-temp-file           Use a temporary file instead of popen to read
                                   the preprocessor output
         --no-use-temp-file        Use popen (default)
      -r                           Ignored for compatibility with rc
      @&lt;file&gt;                      Read options from &lt;file&gt;
      -h --help                    Print this help message
      -V --version                 Print version information
    FORMAT is one of rc, res, or coff, and is deduced from the file name
    extension if not specified.  A single file name is an input file.
    No input-file is stdin, default rc.  No output-file is stdout, default rc.
    C:\msys64\mingw64\bin\windres.exe: supported targets: pe-x86-64 pei-x86-64 pe-bigobj-x86-64 elf64-x86-64 pe-i386 pei-i386 elf32-i386 elf32-iamcu pdb elf64-little elf64-big elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex plugin
    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  cmake/public/cuda.cmake:47 (enable_language)
  cmake/Dependencies.cmake:44 (include)
  CMakeLists.txt:865 (include)


-- Configuring incomplete, errors occurred!
</code></pre>