Source: https://mokxi.com/errors/function-definition-is-not-allowed-here
Updated: 2026-11-16

Home / Errors
Arduino build error

# error: a function-definition is not allowed here before '{' token

A function can only be defined at the top level of the file. This one sits inside the curly brackets of another function.

Try the fixed sketch in Mokxi See the causes

- Build error
- 2 common causes
- Seen 2,761 times in failed builds on Mokxi in the 30 days to November 16, 2026.

The message

## What the Arduino IDE prints

Output window

It nearly always means a closing brace is missing above it, so the compiler thinks the earlier function is still open.

Mokxi's compiler, clang, words it as function definition is not allowed here.

Causes

## The 2 usual causes with the fix

### 1A closing brace is missing before the new function

The function above never closed, so the next one starts inside it. Add the brace.

Broken

Fixed

Mokxi’s build tab says: A function starts inside another one.

Try this fix in Mokxi

### 2A helper function was written inside setup()

C++ has no functions inside functions. Move the helper out, above or below setup().

Broken

Fixed

Mokxi’s build tab says: A function starts inside another one.

Try this fix in Mokxi

FAQ

## Questions and answers

### What does this error mean?

A function definition, with its own curly brackets, was found inside another function. C++ does not allow that.

### Why does it point at a function that looks fine?

The real fault is a missing brace above it. The function it names is only where the compiler noticed.

### Where should my own functions go?

At the top level of the sketch, outside setup() and loop(). In a .ino file their order does not matter.

Next

## More errors and the longer guide

- error: expected '}' at end of input
- error: expected unqualified-id before 'if'

The longer guide to this error All Arduino errors
