Try to build cpp extension on Win10 but got "fatal error C1021: invalid preprocessor command 'warning'"

I followed the instruction of this to build a custom cpp extension.

The extension code works fine on Ubuntu but fails on Win10.
When I run python setup.py install it gives bunches of warnings and an error like below:

C:\Users\jiang\Miniconda3\envs\pytorch\lib\site-packages\torch\lib\include\torch\csrc\api\include\torch/torch.h(7):
fatal error C1021: invalid preprocessor command ‘warning’
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe’ failed with exit status 2

I didn’t paste those warnings because there are too many.

Anyone knows how to fix this?

Thank you!

I think your Visual Studio might be too old.
@peterjc123 suggested in another thread to update VS to 15.3.

1 Like

pragma warning with VS2017

C:\Users\tobai\AppData\Local\conda\conda\envs\IRIS30\lib\site-packages\torch\lib\include\torch\csrc\api\include\torch/torch.h(7): fatal error C1021: invalid preprocessor command 'warning’error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe’ failed with exit status 2

Looks like #warning preprocessor command is invalid in MSVC. I’m find a portable way to do this.