Weird C++ error with Slate

It sounds like you might have a cyclic include (header 1 including header 2 which also includes header 1 - there may be several levels of #include indirection within the cycle).

Provided you don’t need to use the defined widget type in your header (eg, call a function on it), you can just remove the include from the header and add it to the cpp file instead, you can then just use a forward declaration in the header.

Hello,

We have some widgets for Slate, coded in C++, that are used in a “uimain” class which contains some TSharedRef<...> to these widgets.
When using unit builds (the default for Unreal), everything compiles and work correctly. However, when switching to normal builds (no unit builds, much faster), we have the error

TSharedRef<SMyWidget> w; // 'SMyWidget' : undeclared identifier

Also, using a raw pointer change the error to:

SMyWidget* w; // syntax error: missing ';' before '*'

Headers are correcly included, it is as if the widget class got ‘eaten’ by the compiler…

So, the questions are:

1/ Why such an error ?

2/ How to get rid of it (while keeping normal non-unit builds) ?

That was effectively a circular include dependency, thanks !
PS: I see no ‘comment’ button, so I make a new answer. I also cannot upvote (“request method not allowed”) nor accept the answer…