Yes, PyTorch can do it, but you need to import the right header, I think
#include <torch/extension.h>
will do the trick.
The background is that the Python bits are the thing you would not want to include when you are using libtorch purely in C++, so you want more than just torch/torch.h
if you use Python.
Best regards
Thomas