Declaration error when compiling LibTorch with 3rd party

I am developing a physics informed neural network code for an OpenFOAM application in my thesis studies. I am stuck when I include libtorch into the code, inside a specific class. The compiler complains about some declaration error, which is coming from the libtorch, however, if I include it into another class, it works well. Unfortunately, I need to include torch headers in that problematic class to get access to the objects I need for DNN inference.

/opt/openfoam7/src/OpenFOAM/lnInclude/className.H:40:34: error: two or more data types in declaration of ‘typeName_’
   40 |     static const char* typeName_() { return TypeNameString; }

/opt/openfoam7/src/OpenFOAM/lnInclude/typeInfo.H:72:19: error: ‘word’ does not name a type; did you mean ‘word_H’?
   72 |     virtual const word& type() const { return typeName; }

/home/sergen/torch/files/libtorch/include/c10/util/typeid.h:437:38: error: expected unqualified-id before ‘noexcept’
  437 |   static c10::string_view TypeName() noexcept {

/home/sergen/torch/files/libtorch/include/c10/core/TensorImpl.h: In member function ‘T* c10::TensorImpl::data() const’:
/home/sergen/torch/files/libtorch/include/c10/core/TensorImpl.h:1184:27: error: ‘TypeName’ is not a member of ‘caffe2::TypeMeta’
 1184 |         caffe2::TypeMeta::TypeName<T>(),

/home/sergen/torch/files/libtorch/include/c10/core/TensorImpl.h:1184:37: error: expected primary-expression before ‘>’ token
 1184 |         caffe2::TypeMeta::TypeName<T>(),

and so on

Any help is appreciated,

Kind regards