0

Problem:

error LNK2019: unresolved external symbol "public: __thiscall Vector3::Vector3(void)" (??0Vector3@@QAE@XZ) referenced in function _WinMain@16

Details:

I have a custom Vector3 class with its basic constructor Vector3() which is declared in the Maths.h file:

    struct Vector3
    {
        float x;
        float y;
        float z;

        Vector3();
     ...
     }

and defined in Maths.cpp:

    Vector3::Vector3()
    {
        this->x = 0;
        this->y = 0;
        this->z = 0;
    }

Module "Maths" is a part of a DLL. As long as I use the Vector3 class within the modules of the DLL it's business as usual. However in the specific case when I try to define it in the executable which links with the DLL, I get unresolved external symbol. E.g.:

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
        ...
        Vector3 a = Vector3();
        ...
    }

I have found a workaround. If I perform the definition in the Maths.h itself and ommit it in Maths.cpp entirely, like this:

    struct Vector3
    {
        float x;
        float y;
        float z;

        Vector3()
        {
           this->x = 0;
           this->y = 0;
           this->z = 0;
        }
     ...
     }

it works. But I have no idea what the problem was and why it manifested itself only in this specific case.

pseudomarvin
  • 1,477
  • 2
  • 17
  • 32
  • 1
    Is the definition actually being exported? I ask because I don't see any macro machinery (or similar) in the `Vector` struct of your question. – James Adkison Sep 23 '15 at 19:43
  • 1
    If you creating a DLL with VS, check "Export Symbols". It will create the relevant __declspec entries. Have a look at https://msdn.microsoft.com/en-us/library/a90k134d.aspx if you are not using Visual Studio – cup Sep 23 '15 at 19:53
  • Okay I see, I was exporting the DLLfunctions being called from the platform layer(Init, Update and Release) by using "__declspec(dllexport)" semantic but that was it. So I either define the constructor in the header file which does it since the header file is inlined in th executable or I export it explicitly from the module, that means that the linker goes into the obj and searches for the definition and brings that to the executable. Am I understanding correctly? Thanks. – pseudomarvin Sep 24 '15 at 09:07

0 Answers0