C Compiler Logo

Undefined Reference to Function

Undefined Reference to Function

linker

undefined reference to 'customFunction'

Description

The linker cannot find the implementation of a function that is called in the code.

Common Causes

Example of Error

Error Code

// In main.c
void customFunction();  // Declaration

int main() {
    customFunction();  // Call
    return 0;
}

// Missing definition of customFunction

Solution

Provide the definition for the function or link to the library that contains it.

Corrected Code

// In main.c
void customFunction();  // Declaration

int main() {
    customFunction();  // Call
    return 0;
}

// Definition
void customFunction() {
    printf("Custom function called\n");
}

Additional Tips