'xxx' uses undefined class 'WORLDBROWSER_API' error

Hi,

Since Unreal Engine 4.20, I’m getting a ‘FLevelModel’ uses undefined class ‘WORLDBROSWER_API’ error in UE Engine’s LevelModel.h while trying to compile an HostProject (to compile a plugin).

As I saw in another thread (https://answers.unrealengine.com/questions/769047/loading-umaps-into-leveleditor.html), I’ve added:

PublicIncludePaths.AddRange(new string[]
 {
     Path.Combine(EngineDirectory, "Source/Editor/WorldBrowser/Public"),
     Path.Combine(EngineDirectory, "Source/Editor/WorldBrowser/Private")
 });

to either the hostproject’s and plugin’s Build.cs but the error is still there.

The error is in LevelModel.h on line 30:

class WORLDBROWSER_API FLevelModel
	: public TSharedFromThis<FLevelModel>
{...}

(I get the same error with FLevelCollectionModel.h as well)

How could I fix this?

That header file are in private directory it is not intended to be accessed outside the module that it is, it actully makes me wonder why you didn’t get linker errors from this

This macro pastes extern in case that module is compiled in to sperate dll. First of all you should make usre you add dependence for WorldBrowser module, UBT at that case should automatically solve all pathing and macro issues. If thats not work there other hack you can use, do #define WORLDBROWSER_API before include and #undef WORLDBROWSER_API after it, but again it is a hack to satisfy the compiler ;p so there might be even more serious issues, but if it worked for you in 4.19 then it will work the same as in that version.

The main issue is you trying to access header file from private, if you making plugin for market place you might have issues getting passed the submission checks.

As I come to a similiar problem but with another background, I have a question regarding these “_API - Definitions” . Why do I need this, or why do Unreal need this?