How to expose a c++ function to another plugin in ue4

  • I have written a class in a new plugin and add a static function to get some data.

                         static float FGDALIntegrationPluginModule::getGDALOriginData()  
    
  • And I have added that plugin to another plugin through .uplugin file and also add the modules for the build.cs file

“Plugins”: [
{
“Name”: “UnrealGDAL”,
“Enabled”: true
}
]

-But I cannot access the static function from the first plugin

PublicDependencyModuleNames.AddRange(
new string[]
{
“Core”,“GDAL”,“UnrealGDAL”
// … add other public dependencies that you statically link with here …
}

  • What can I do for this

Hello! Each module is compiled to dll, so everything that you want to use in another module should be having module export macro (that is ending with _API). Can you provide .h file for this class?

Hi thank you very much for your comment.
This is the header file of the integration plugin.

#pragma once
#include “CoreMinimal.h”
#include “Modules/ModuleManager.h”

class FGDALIntegrationPluginModule :
public IModuleInterface
{
public:

/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;

static float getGDALOriginData();

};

And I exposé this function as below. But it does not work

float a=FGDALIntegrationPluginModule::getGDALOriginData();

1 Like

this is old but I came across is trying to figure the same thing in case someone finds it.

The static method is missing the export macro. Unreal makes one for you for each module.

For example, if your module is named FCoolThingModule then the export macro is FCOOLTHING_API. Typically your module headers will include this next to classes and structs like class FCOOLTHING_API UFooBar {
This would let other modules outside of CoolThingModule see the FooBar class and be able to reference it.

In the above case there are 2 choices to make in the header file:

Just expose the method like so:

FCOOLTHING_API static float getGDALOriginData()

OR

Expose the whole class, like I said before with UFooBar

1 Like