PyTorch 1.2 linker error on Windows related to THP_CORE preprocessor definition

Hi everyone,
I’m trying to update an extension module of mine.
However, I am getting linker errors when building with msvc15: About THPVariableClass not being defined.
I could resolve it by removing the THP_CORE preprocessor definition, which seems to be used to activate __declspec(dllexport) as opposed to __declspec(dllimport).
I think that the flag came in from the caffe2 CMake target.

My question is whether it is the right thing to do, simply undefining THP_CORE.

No, actually, you should link against _C.lib instead of changing the code.

I forgot to mention, that I used the CMake package in site-packages/torch/share/cmake to specify the PyTorch dependency:
target_link_libraries(torch_plus_ops ${TORCH_LIBRARIES}).

_C.lib does not define the symbol either. Also, when using __declspec(dllexport), the linker would not look for the symbol in imported libraries, right?

I checked and succeeded building without the “Torch” CMake package and instead used the compiler/linker flags from torch.utils.cpp_extension.