Download

'Unresolved externals' error only while using project module name in class

The following line leads to an unresolved externals error:


UCLASS()
class  MyProjectModule ACustomVolume public AVolume


while this doesn’t:


UCLASS()
class  ACustomVolume  : public AVolume

I understand from another thread that 4.5 will carry a fix for AVolume to ensure it exports the class definition and presumably that will fix the first snippet as well, but can someone explain why the first snippet fails while the second works? Also I’m not sure what the implication of not having my project module stamped on the class is as that hasn’t caused me any problems (yet).

Perhaps this is more of a C++ question than a specific UE4 question so apologies if it turns out to be the former (time to dust off my decade old C++ books it would seem :slight_smile: )

This is not valid C++ syntax, base classes must be specified after a colon (as in your second snippet). And, perhaps you meant to use MYPROJECTMODULE_API instead of MyProjectModule. The _API macro when applied to a class declaration will export the entire class from the module, generally you’d only want to do this if you plan on sub-classing that class in another module.

My apologies, both the missing colon and API bit are typos I made when I wrote that out (embarrassed :eek: )

Your explanation of the API part is useful and answers my question of why one would prefer one over the other.


UCLASS()
class  MyProjectModule_API ACustomVolume : public AVolume


So I guess the snippet works when I remove the module tag as it has access to all classes regardless of whether or not they’ve been exported? IIRC the 4.5 fix was to export AVolume which will allow its usage in custom modules if I understand this right.

My apologies, both the missing colon and API bit are typos I made when I wrote that out as an example (embarrassed :eek: )

Your explanation of the API part is useful and answers my question of why one would prefer one over the other.


UCLASS()
class  MyProjectModule_API ACustomVolume : public AVolume


So I guess the snippet works when I remove the module tag as it has access to all classes regardless of whether or not they’ve been exported? IIRC the 4.5 fix was to export AVolume which will allow its usage in custom modules if I understand this right.

C++ is case-sensitive, so MYPROJECTMODULE_API must be in all caps, otherwise the compiler will just see an undefined symbol and won’t know what to do with it.