Linker Errors using DetourNode.h in Navmesh module

Hey,

I am trying to change the FindPath function in ARecastNavMesh. Everything works except I wrote a custom class that has dtNavMeshQuery as parent with a findCustomPath() function.

Visual studio compiles fine but when UE4 rebuilds the binaries it gives me these linker errors:

[2/3] Link UE4Editor-MyGame.dll
   Creating library D:\Unreal\GAME\MyGame\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyGame.lib and object D:\Unreal\GAME\MyGame\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MyGame.exp
Module.MyGame.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl dtNodePool::clear(void)" (?clear@dtNodePool@@QEAAXXZ) referenced in function "public: unsigned int __cdecl dtNavMeshCustomQuery::findCustomPath(class UObject const *,unsigned __int64,unsigned __int64,float const *,float const *,class dtQueryFilter const *,struct dtQueryCustomResult &,float *)const " (?findCustomPath@dtNavMeshCustomQuery@@QEBAIPEBVUObject@@_K1PEBM2PEBVdtQueryFilter@@AEAUdtQueryCustomResult@@PEAM@Z)
Module.MyGame.cpp.obj : error LNK2019: unresolved external symbol "public: struct dtNode * __cdecl dtNodePool::getNode(unsigned __int64)" (?getNode@dtNodePool@@QEAAPEAUdtNode@@_K@Z) referenced in function "public: unsigned int __cdecl dtNavMeshCustomQuery::findCustomPath(class UObject const *,unsigned __int64,unsigned __int64,float const *,float const *,class dtQueryFilter const *,struct dtQueryCustomResult &,float *)const " (?findCustomPath@dtNavMeshCustomQuery@@QEBAIPEBVUObject@@_K1PEBM2PEBVdtQueryFilter@@AEAUdtQueryCustomResult@@PEAM@Z)
Module.MyGame.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl dtNodeQueue::dtNodeQueue(int)" (??0dtNodeQueue@@QEAA@H@Z) referenced in function "public: unsigned int __cdecl dtNavMeshCustomQuery::findCustomPath(class UObject const *,unsigned __int64,unsigned __int64,float const *,float const *,class dtQueryFilter const *,struct dtQueryCustomResult &,float *)const " (?findCustomPath@dtNavMeshCustomQuery@@QEBAIPEBVUObject@@_K1PEBM2PEBVdtQueryFilter@@AEAUdtQueryCustomResult@@PEAM@Z)
Module.MyGame.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl dtNodeQueue::~dtNodeQueue(void)" (??1dtNodeQueue@@QEAA@XZ) referenced in function "public: void * __cdecl dtNodeQueue::`scalar deleting destructor'(unsigned int)" (??_GdtNodeQueue@@QEAAPEAXI@Z)
Module.MyGame.cpp.obj : error LNK2019: unresolved external symbol "private: void __cdecl dtNodeQueue::bubbleUp(int,struct dtNode *)" (?bubbleUp@dtNodeQueue@@AEAAXHPEAUdtNode@@@Z) referenced in function "public: unsigned int __cdecl dtNavMeshCustomQuery::findCustomPath(class UObject const *,unsigned __int64,unsigned __int64,float const *,float const *,class dtQueryFilter const *,struct dtQueryCustomResult &,float *)const " (?findCustomPath@dtNavMeshCustomQuery@@QEBAIPEBVUObject@@_K1PEBM2PEBVdtQueryFilter@@AEAUdtQueryCustomResult@@PEAM@Z)
Module.MyGame.cpp.obj : error LNK2019: unresolved external symbol "private: void __cdecl dtNodeQueue::trickleDown(int,struct dtNode *)" (?trickleDown@dtNodeQueue@@AEAAXHPEAUdtNode@@@Z) referenced in function "public: unsigned int __cdecl dtNavMeshCustomQuery::findCustomPath(class UObject const *,unsigned __int64,unsigned __int64,float const *,float const *,class dtQueryFilter const *,struct dtQueryCustomResult &,float *)const " (?findCustomPath@dtNavMeshCustomQuery@@QEBAIPEBVUObject@@_K1PEBM2PEBVdtQueryFilter@@AEAUdtQueryCustomResult@@PEAM@Z)
Module.MyGame.cpp.obj : error LNK2001: unresolved external symbol "struct FThreadSafeStaticStat<struct FStat_STAT_Navigation_RecastPathfinding> StatPtr_STAT_Navigation_RecastPathfinding" (?StatPtr_STAT_Navigation_RecastPathfinding@@3U?$FThreadSafeStaticStat@UFStat_STAT_Navigation_RecastPathfinding@@@@A)
D:\Unreal\GAME\MyGame\Binaries\Win64\UE4Editor-MyGame.dll : fatal error LNK1120: 7 unresolved externals

It is mainly LNK2019… I did add “Navmesh” to my dependencies and included “DetourNode.h” where all the classes and structs are declared.
Does anyone have any idea how to solve these errors? I have been searching a while on my own now but cannot make sense of it.

Help greatly appreciated :slight_smile:

Elias

Okey so after searching for a while I found out it has to do with the “DetourNode.h” file.

The classes in there use inline functions and the the compiler gives the errors if I use the functions which code are in the “DetourNode.cpp”. Because he can’t find them or something?

Is there a way I can make the compiler compile “DetourNode.h” completly first?

I was able to resolve the last Linker error : LNK2001 by commenting out SCOPE_CYCLE_COUNTER(STAT_Navigation_RecastPathfinding);

No progress on the other errors :confused:

Bump,

If you want to try it out yourself add “Navmesh” to your dependencies and include “DetourNode.h” and try to create a dtNodeQueue, this is already enough to get the linker errors…

edit: DetourQueue → dtNodeQueue

Visual Studio is giving you errors because it can’t find the definitions of the functions you are using from DetourNode.h. This is because those functions have not been flagged for export by the Unreal API. You did the right thing by adding the module to your dependencies, but that only gives you access to exported functions/classes. Notice how the class rcContext in Recast.h contains the keyword “NAVMESH_API”. This means that this class is publicly accessible by adding the module. If you have a source build of the engine, you can export the functions you need yourself. For example, if you want access to the dtNodePool class and its functions, replace line 47 of DetourNode.h with “class NAVMESH_API dtNodePool”. This should resolve the linking errors, since the compiler will now be able to access those function and class definitions. You will need to manually add the API keyword before every non-exported class you want to use and then recompile the engine from source.