Creating module. Virtual function error

Hello,
I’m trying to create a module. I have a class

//TestModule.h
class FTestModule : public IModuleInterface

Inside it I declare some method. Next, I’m implementing this module

//TestModule.cpp
#include "TestModule.h"
IMPLEMENT_MODULE(FTestModule, TestModule)

The most interesting part for me, which goes me crazy - if I define my method in *.h, everything works. But if in *.h I have only declaration and define this method in *.cpp I always get an error:

error LNK2019: unresolved external
symbol “public: int __cdecl
FTestModule::Test(int)”
(?Test@FTestModule@@QEAAHH@Z)

What is this and how to fix? Thank you.

How are you defining your FTestModule::Test(int) in your cpp file?

Check that when you define in your cpp, you’re using

int FTestModule::Test(int Argument) { // your awesome code here }
and not just
int Test(int Argument) { //still your awesome code here }

Also, use int32 instead of int as the size of an int can vary between platforms (4 bytes on 32bit systems and 8 bytes on 64bit systems). int32 provides an integer type that is always 4 bytes in size.

Hi. Yeah, this is just an example so I tried to keep things simple. I created a post in forums where I described a problem more precisely:

Class functions are not automatically exported from modules. You have to mark up your Test() function with the export macro for your module, i.e.:

TESTMODULE_API void Test();

Alternatively, you can also export the entire module class, although that is probably overkill:

class TESTMODULE_API FTestModule

Note that the export macro is automatically generated for all your modules. The naming convention is MODULENAME_API where ‘MODULENAME’ is the all-uppercase version of your module’s name.

Hello. Thank you for the answer. Small question - how does engine modules works without MODULENAME_API? For example, FAnalyticsET.

The type FAnalyticsET is never used outside of the AnalyticsET module. Instead it is accessed through the publicly known IAnalyticsProviderModule interface that it implements. This allows you to implement many different analytics providers without actually knowing any of them explicitly.