C Compiler Logo

Undefined Reference to Main

Undefined Reference to Main

linker

undefined reference to 'main'

Description

The linker cannot find the main function, which is the entry point of a C program.

Common Causes

Example of Error

Error Code

// No main function defined
void setup() {
    // Initialize program
}

void loop() {
    // Run program
}

Solution

Add a properly defined main function to your program.

Corrected Code

int main() {
    setup();
    
    while (1) {
        loop();
    }
    
    return 0;
}

void setup() {
    // Initialize program
}

void loop() {
    // Run program
}

Additional Tips