I decided to move one of interfaces to plugin, but without any results:(
At last I took interface from wiki example, checked it,
and then move it to plugin. And it stopped working.
Project compliles if interface has no methods, so, it’s visible from main module.
But with any method added I got errors like:
error LNK2001: unresolved external symbol “public: virtual class FString __cdecl IToStringInterface::ToString(void)” (?ToString@IToStringInterface@@UEAA?AVFString@@XZ)
What am I doing wrong?
Clearly the linker can’t find the implementation of your method.
To say why exactly, you need to show all the relevant code, .h and .cpp. Might be worth posting your .build.cs files too.
That’s because the IInterface portion usually does NOT come with the <Name>_API macro and therefore won’t be exported. This isn’t a problem if the interface is part of the module that want’s to use it and only becomes an issue if both the interface and the “user” of the interface (that wants to call the interface function) are in different (game/engine)modules or plugins. The easy fix would be to simply add the <Name>_API macro to the IInterface as well.
On a side note, if ToString was a UFUNCTION you’d have to call IToStringInterface::Execute_ToString(). The problem and solution are the same as described above though.
I believe this is the wiki we’re talking about: Interfaces in C++
Yes.
Thanks a lot, I added API to class declaration, following your advice, and it works fine now.