CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2014
    Posts
    2

    LNK2001: unresolved external symbol when building for x64 platform

    The project builds on Win32 platform, but not on x64.

    Full error message: dllentry.obj : error LNK2001: unresolved external symbol "class CFactoryTemplate * g_Templates" (?g_Templates@@3PAVCFactoryTemplate@@A)

    The dllentry.cpp (a DirectShow base class) compiles on both platforms. It contains the external declarations:

    extern CFactoryTemplate g_Templates[];
    extern int g_cTemplates;

    g_Templates[] is then used in two functions:

    __control_entrypoint(DllExport) STDAPI DllGetClassObject(__in REFCLSID rClsID,
    __in REFIID riid, __deref_out void **pv)
    {
    ...
    for (int i = 0; i < g_cTemplates; i++)
    {
    const CFactoryTemplate * pT = &g_Templates[i];
    }
    }

    and

    DllInitClasses(BOOL bLoading)
    {
    ...
    for (int i = 0; i < g_cTemplates; i++)
    {
    const CFactoryTemplate * pT = &g_Templates[i];
    }
    }

    myClass.cpp contains the definitions for the two externals in dllentry.cpp, at top level, just after the includes:

    CFactoryTemplate* g_Templates=0;
    int g_cTemplates=0;

    myClass.cpp also compiles by itself, but the project does not build. I checked all the libraries in the project settings and all seems to be OK, the 64 bit versions are used.

    What should I do to make the project build for x64 platform?

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: LNK2001: unresolved external symbol when building for x64 platform

    the Obvious first suggestion would be that it seems that either myclass.cpp isn't properly defined and the 2 definitions don't get compiled (possibly due to improper placement of the compiled header include, or due to conditional compilation switches (#if/#ifdef)
    Alternatively, the myclass.obj isn't being considere in the linking process, indicating a problem with the makefile or the linker settings.

  3. #3
    Join Date
    May 2013
    Posts
    26

    Re: LNK2001: unresolved external symbol when building for x64 platform

    How are your DirectX SDK's set up? Perhaps a missing lib from the x64.

  4. #4
    Join Date
    Jul 2014
    Posts
    2

    Re: LNK2001: unresolved external symbol when building for x64 platform

    Thanks, guys. I solved it by declaring
    CFactoryTemplate g_Templates[1];
    in MyClass.cpp, instead of
    CFactoryTemplate* g_Templates=0;

    For some reason the win32 build did not complain about pointer to array conversion, but the x64 build seems not to like it.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: LNK2001: unresolved external symbol when building for x64 platform

    now your definition and the declaration differ, that's not an ideal situation either (even if the linker isn't complaining), it could cause some headaches down the road...

    if you really intend for it to be a pointer, then define it as such in the header as well (and duplicate it in the declaration in the .cpp)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured