Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

LNK2019 Unresolved External Symbol, Can't figure out why?

apologies in advance as this is most likely my own impotence to find the error and simply overlooking the answer.
Anyway; when invoking XEngine::MapConstBufferData in my entry point I run into LNK2019, I’m quite clueless as to why but believe the error to lay within the fact that it is template function, all help is highly appreciated!

XTypes.h

struct TRANSLATE2D
{
    FLOAT OffsetX, OffsetY;
};

XEngine.h

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

template <class BufferType>
VOID MapConstBufferData(ComPtr<ID3D11Buffer> Buffer, BufferType BufferData, UINT Size);

XEngine.cpp

template <class BufferType>
VOID XEngine::MapConstBufferData(ComPtr<ID3D11Buffer> Buffer, BufferType BufferData, UINT Size)
{
    Contents are irrelevant. 
}

EntryPoint.cpp

INT MAIN
{
    XTYPES::TRANSLATE2D Translate{};
    Engine.MapConstBufferData<XTYPES::TRANSLATE2D>(Engine.GetConstBuffer(), Translate, sizeof(XTYPES::TRANSLATE2D));
    // ^ LNK2019: Unresolved External 

    Contents are irrelevant. 

}

>Solution :

templates require either header-file only implementation, or explicit instantiation.

The compiler can’t code the template when it sees it in EntryPoint.cpp as it doesn’t have the rules.

The compiler doesn’t realize it needs it when it sees it in XEngine.cpp

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading