CppPilot

Compiler diagnostic Visual Studio C++

C3861 identifier not found

The code calls a function the compiler has not seen declared at that point. Unlike C, C++ never declares a function implicitly.

Applies toMSVC on Windows; code and debugger concepts apply to MSBuild and CMake
ExamplesFocused excerpts; required context is stated alongside each example

Visual Studio property-page paths describe MSBuild projects. For CMake, configure the corresponding target or preset. Menu names can vary by Visual Studio version; use the cited reference for your toolset.

Build output
error C3861: 'Compute': identifier not found

Causes & corrections

Find the case that matches your build. Each example shows what changes and why.

  1. The function is defined below the call.

    Declare it before the call (int Compute(int);), in a header or at the top of the file, or move its definition above.

    Problem

    int main() { return Compute(3); }int Compute(int x) { return x * 2; }

    Correction

    int Compute(int);int main() { return Compute(3); }int Compute(int x) { return x * 2; }
    Note 1The declaration must precede the call, even if the definition is later in the same file.
    VideoFilmed in Visual Studio: this case fixed by hand, then with CppPilot. English narration, with subtitles in English, French, German, Italian and Spanish.
    Transcript

    C3861, identifier not found: fixed by hand, then with CppPilot. main calls Average, but Average is defined below main.

    The build fails with C3861: Average, identifier not found. The compiler reads the file from top to bottom.

    Declare the function before main. Build again: the call now matches a declaration, and the build succeeds.

    Now the same error, fixed by CppPilot. After the failed build, select the error in the Error List, and click Fix with CppPilot.

    Click Fix on the C3861 card. The AI sees that Average is defined after main, and adds its declaration before main.

    CppPilot rebuilds the project to check the fix: the error is resolved. CppPilot explains and fixes C++ build errors in Visual Studio.

  2. The header that declares it is not included.

    Include it: std::max needs <algorithm>, printf needs <cstdio>.

    Problem

    // <algorithm> missingint largest = std::max(2, 3);

    Correction

    #include <algorithm>int largest = std::max(2, 3);
    Note 2Include the function's own header instead of relying on transitive includes.
  3. The function is in a namespace.

    Qualify it, for example std::sort or utils::Compute.

    Problem

    namespace utils { int Compute(int); }int main() { return Compute(3); }

    Correction

    namespace utils { int Compute(int); }int main() { return utils::Compute(3); }
    Note 3Qualification names the intended declaration; its definition must still be linked.
  4. The function is inside #ifdef.

    Its declaration may be excluded for this configuration or platform: check the preprocessor definitions of the configuration you build.

    Problem

    #ifdef ENABLE_TRACEvoid trace();#endifvoid run() { trace(); }

    Correction

    #ifdef ENABLE_TRACEvoid trace();#endifvoid run() {#ifdef ENABLE_TRACE    trace();#endif}
    Note 4Keep the declaration and call consistent in configurations with the feature disabled.

Sources and scope

Official references

These links document the compiler, build system, or debugger behavior discussed here. Use the version selector on Microsoft Learn for your toolset. Example blocks are focused excerpts; required headers and build settings are stated alongside them.

In your workspace

Investigate C3861 with CppPilot

CppPilot gives the selected AI the diagnostic, relevant code, and project settings for the active configuration. Choose Fix to request a correction, then check the result with a rebuild.

Use your own Codex or Claude account, or optional CppPilot Cloud access. Setup instructions

Visual Studio Marketplace