Compiler (c++) not compatible with the compiler Pytorch was built

When I’m compiling custom cuda extensions I get the following warning but the extensions still compile and seem to work just fine.

                               !! WARNING !!

Your compiler (c++) is not compatible with the compiler Pytorch was
built with for this platform, which is g++ on linux. Please
use g++ to to compile your extension. Alternatively, you may
compile PyTorch from source using c++, and then you can also use
c++ to compile your extension.

See for help
with compiling PyTorch from source.

                              !! WARNING !!

I had a quick look at the source code of and saw that the accepted compilers on Linux are ['g++', 'gcc', 'gnu-c++', 'gnu-cc']. The compiler used to build the extensions on my Linux machine (5.4.33-3-MANJARO) is /usr/bin/c++. The output of c++ --version is c++ (Arch Linux 9.3.0-1) 9.3.0.

Can someone tell me if there is actually an incompatibility between the compilers or if this is a bug in PyTorch?

Thanks a lot!


I am also getting the same warning with this file address before it :

../python3.7/site-packages/torch/utils/ UserWarning

I think we did not have g++ libraries when we installed pytorch, so it used whatever it found i.e. cpp. Since Pytorch is build on top of g++ for linux. Straightforward solution can be to uninstall and ensure g++ installation first, but I am not sure. If you find a workaround to this problem, let me know.

@MauroPfister Normally different compilers should be compatible as long as they follow the same c++ standard. But we can not guarantee this.

Thanks for the answers @Jayant_Parashar and @glaringlee!

I just do not understand why my compiler ( c++ (Arch Linux 9.3.0-1) 9.3.0) is different from gnu-c++? They do not have exactly the same name, but the arch linux package ( says it is the gnu compiler. I do not have much experience in this area though, so I am happy if someone can correct me!

ArchLinux’s compiler does follow the rolling base of GNU, I would say they should be fully compatible. The reason we still give warning is that ArchLinux is a independent linux distribution, their software might contains their own Proprietary software and is not endorsed by the GNU project.

1 Like