c++unreal-engine5unresolved-external

Several LNK2019 and LNK2001 "unresolved external symbol" errors when compiling modular UE5 C++ source code


I am attempting to build the solution of my Unreal Engine 5 project which consists of several code modules, two of which are CelBody and OrbitSuite. These modules are structured as Epic Games recommends (with private and public folders containing .cpp and .h files, respectively). OrbitSuite is a private dependency of CelBody as it contains a data structure called FBodyData which is the type of one of the ACelBody actor class' member attributes.

The OrbitSuite and CelBody module folders inhabit the same source directory of my Unreal project and #includes are spelled correctly and IntelliSense shows zero issues regarding missing headers or unresolved members. In CelBody.Build.cs, OrbitSuite is included in the PrivateDependencyModuleNames string list which is unedited since the last time the project compiled successfully.

When I attempt to compile, the LNK2019 error reads:

LNK2019: unresolved external symbol "public: __cdecl FBodyData::FBodyData(void)" (??0FBodyData@@QEAA@XZ) referenced in function "public: __cdecl ACelBody::ACelBody(class FVTableHelper &)" (??0ACelBody@@QEAA@AEAVFVTableHelper@@@Z)

Looking up the error code, it apparently signals "when a declaration exists in a header file, but no matching definition is implemented" and, in this case, is referring to FBodyData's default constructor as it is called by the declaration of member FBodyData BodyData in the class definition of ACelBody. I've quadruple checked BodyData.h and BodyData.cpp and the default constructor is defined and implemented correctly.

I'd expect the compiler to have no issue locating the implementation of FBodyData() and fear the error may be caused by something unrelated. Let me know if there are logs it would be helpful to provide or if any more detail is required regarding file structure or class implementation.


Solution

  • As you didn't provide any code I can only guess, but you likely forgot to export your classes to use them in another module.

    // <ModuleName>_API is defined as platform-specific DLL export/import 
    // directives by UBT.
    class CELBODY_API FBodyData
    {
        FBodyData() = default;
    };