Edit

Share via


Compiler Warning (level 2) C5046

'function' : Symbol involving type with internal linkage not defined

Remarks

The compiler has detected a use of a function that doesn't have a definition, but the signature of this function involves types that aren't visible outside this translation unit. Because these types aren't externally visible, no other translation unit can provide a definition for this function, so the program can't be successfully linked.

Types that aren't visible across translation units include:

  • Types declared inside an anonymous namespace

  • Local or unnamed classes

  • Specializations of templates that use these types as template arguments.

This warning is new in Visual Studio 2017 version 15.8.

Example

This sample shows two C5046 warnings:

// C5046p.cpp
// compile with: cl /c /W2 C5046p.cpp

namespace {
    struct S {
        // S::f is inside an anonymous namespace and cannot be defined outside
        // of this file. If used, it must be defined somewhere in this file.
        int f();
    };
}

// g has a pointer to an unnamed struct as a parameter type. This type is
// distinct from any similar type declared in other files, so this function
// cannot be defined in any other file.
// Note that if the struct was declared "typedef struct { int x; int y; } S, *PS;"
// it would have a "typedef name for linkage purposes" and g could be defined
// in another file that provides a compatible definition for S.

typedef struct { int x; int y; } *PS;
int g(PS p);

int main()
{
    S s;
    s.f();      // C5046 f is undefined and can't be defined in another file.
    g(nullptr); // C5046 g is undefined and can't be defined in another file.
}

To fix these issues, define the functions in this file.