Using a compiler other than cl.exe in Windows 10 to compile .cu files

I am trying to use GCC to compile with nvcc as opposed to cl.exe using the command

nvcc -c -o depthconv_cuda_kernel.o depthconv_cuda_kernel.cu --compiler-bindir “C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin” --allow-unsupported-compiler -x cu -Xcompiler -fPIC -std c++11 --gpu-architecture=compute_86 --gpu-code=sm_86 -DGPU -I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/include" -DCUDNN --compiler-options “-DGPU -DCUDNN -fPIC”

I need gcc for the command line options std c++11 as well as -fPIC . It seems nvcc is still looking for MSVC’s cl.exe, how can I change this so it uses the GCC compiler I need?

I get the message:
Failed to run C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/cl.exe (The system cannot find the file specified.
).
nvcc fatal : Failed to preprocess host compiler properties.

The system cannot find the file specified

This reads like a message coming directly from the OS. Is the full path correct (no typos)? Have you tried adding MinGW-w64’s bin directory to the PATH environment variable?

I assume that you are aware that you are in uncharted territory because MinGW-w64 is not a toolchain supported by CUDA.

I have recently been aware of this, so ultimately it seems the answer is I can’t compile with MinGW-w64.

I wouldn’t quite go that far. There may be a way of configuring and hacking nvcc until you get it to work with MinGW-w64. I haven’t tried, and probably very people have. However, if you should get to the point where things seem to work and things go wrong later, e.g. a code generation bug, there will be essentially nobody to help you with that.

Is there a particular reason you cannot use MSVC?

It’s possible that the path to the cl.exe is too long for some process in the chain. Try moving Ming64 closer to root and adjust the PATH-setting accordingly.

Well, I am was trying to replicate a compilation that used the -fPIC and -std c++11 flags to the compiler just to copy some code without any changes that could be problematic down the line, I realize now that I’m not sure this is necessary since Windows .dlls apparently don’t need -fPIC and cl.exe natively supports c++11, I believe. I am new to all this, so if anything I’ve said doesn’t make sense I apologize.

As far as I know, MSVC 2019 has full support for C++11. To my knowledge, there is no equivalent to -fPIC because Windows DLLs work differently than Linux DSOs, i.e. it’s not applicable.