0
votes

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 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];
    }
}

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
Where is the definition (not declaration) of g_Templates? Is it possible that file was omitted from the x64 configuration?dlf
To locate the problem try to remove extern from the line extern CFactoryTemplate g_Templates[];KonstantinL

2 Answers

1
votes

You stated in a comment to an earlier answer

The other, valid definition, is in myClass.cpp (main class of my project) 'CFactoryTemplate* g_Templates=0;' followed by 'int g_cTemplates=0;' at the uppermost level in the file, just after the includes.

Your definition of of g_Templates is inconsistent with its declaration.

The declaration is

extern CFactoryTemplate g_Templates[];

This declares g_Templates as an array of CFactoryTemplate (of unknown size). But your definition of

CFactoryTemplates* g_Templates = 0;

defines it as a pointer to a CFactoryTemplate, which is not the same thing.

Therefore, you failed to provide a definition of g_Templates that matches the declaration, and the error message is correct.

You need to get the declaration and definition to agree. One way is to write

CFactoryTemplates g_Templates[1];

to create a definition that is consistent with the declaration. (Note that zero-length arrays are disallowed in C++, so instead we create an array of length 1 and ignore the element in it.)

Another is to change the declaration to

extern CFactoryTemplates* g_Templates;
0
votes

The statement extern CFactoryTemplate g_Templates[]; does not actually define an array* named g_Templates; it simply states that one exists somewhere in the project. You are essentially telling the compiler "don't worry that you don't see this thing anywhere; when it comes time to link, you'll be able to find it in a different module." Except that apparently isn't true. Two possible reasons I can think of are (1) The file that contains the actual definition of g_Templates is not being included in the x64 build configuration, and (2) the definition, wherever it is, is surrounded with something like #ifdef x86.

To solve this, you'll need to locate the actual definition of g_Templates (maybe search for "CFactoryTemplate g_Templates[") and then determine why it is being omitted in the x64 build.


* Technically it is treated as a pointer here