unresolved external symbol “public: int __cdecl UTestClass::GiveFoo(void)” (?GiveFoo@UTestClass@@QEAAHXZ) referenced in function “private: __cdecl UMyObject::UMyObject(class FObjectInitializer const &)” (??0UMyObject@@AEAA@AEBVFObjectInitializer@@@Z)
What is the best way to get rid of the link error. By adding it to the PublicAdditionalLibraries in the Build.cs. I thought, but so far I have no luck.
You need to have the XXX_API in your class declaration and get rid of the MinimalAPI specifier, like this:
UCLASS()
class XXX_API UTestClass : public UObject
{
...
The XXX in XXX_API should be the name of your module. So if your module name is “MyPlugin”, it should be MYPLUGIN_API. If you have the UE4 editor generate a new UObject class from a template for you, it should show you an example of how it should look.
If you don’t do these things, the symbols will not be exported to other modules, so only code in that plugin will be able to use the methods of your class. That’s why you get ‘Unresolved external symbol’ during linking.
No problem! By the way, if you add a comment in AnswerHub, it removes the “answered” flag, and you have to set it again manually. (Sorry to ask you to do that, but I want other people to find it in the future.)
Edit: just realized I probably ended up removing it by replying, haha