ESP-IDF LVGL Error: build/config/sdkconfig.h:939:39 expected identifier before string constant (CONFIG_LV_FONT_CUSTOM_DECLARE)
📚 Table of Contents
If you are seeing this error after exporting your UI from SquareLine Studio and rebuilding your project in ESP-IDF v5.x, you are not alone.
The build suddenly fails with something like:
build/config/sdkconfig.h:939:39: error: expected identifier or '(' before string constant
#define CONFIG_LV_FONT_CUSTOM_DECLARE ""
Sometimes the error trace continues into internal LVGL files such as:
lv_disp.c
The confusing part? You never modified those files.
Why This Error Is So Confusing
The compiler points to:
build/config/sdkconfig.h
Or even deeper inside:
components/lvgl__lvgl/src/core/lv_disp.c
But remember:
Error location does not always mean root cause.
Understanding LVGL Configuration in ESP-IDF v5.x
When LVGL is integrated as a component in ESP-IDF, configuration is handled via Kconfig.
You configure it using:
idf.py menuconfig
The settings are stored in:
sdkconfig
And macros are auto-generated into:
sdkconfig.h
In ESP-IDF integration, Kconfig overrides lv_conf.h.
Root Cause Analysis
This is the problematic macro:
#define CONFIG_LV_FONT_CUSTOM_DECLARE ""
Inside LVGL internal config:
#define LV_FONT_CUSTOM_DECLARE CONFIG_LV_FONT_CUSTOM_DECLARE
After macro expansion, the compiler effectively sees:
#define LV_FONT_CUSTOM_DECLARE ""
But LVGL expects something like:
extern lv_font_t ui_font_MyFont;
A string literal is not a valid C declaration — therefore the compiler throws the error.
Proper Fix (Recommended)
Run:
idf.py menuconfig
Navigate to:
Component config → LVGL configuration → Custom font declaration
If unused, disable it.
Then clean and rebuild:
idf.py fullclean idf.py build
Quick Debug Fix (Temporary)
Edit:
sdkconfig
Change:
CONFIG_LV_FONT_CUSTOM_DECLARE=""
To:
# CONFIG_LV_FONT_CUSTOM_DECLARE is not set
Then rebuild.
Key Takeaway
ESP-IDF is not Arduino.
Configuration is controlled by Kconfig.
Understanding how sdkconfig generates macros can save hours of debugging.
In embedded systems, fixing the error is easy. Understanding why it happens is what makes you an engineer.
Fix CONFIG_LV_FONT_CUSTOM_DECLARE Error via ESP-IDF PowerShell (Step-by-Step)
If you are seeing this error:
build/config/sdkconfig.h:939:39: error: expected identifier or '(' before string constant
#define CONFIG_LV_FONT_CUSTOM_DECLARE ""
The safest and most reliable way to fix it is through ESP-IDF PowerShell using menuconfig.
Step 1 — Open ESP-IDF PowerShell
Click the Start Menu and open:
ESP-IDF 5.3 PowerShell
Step 2 — Navigate to Project Directory
Use the cd command to open your project folder:
cd C:\Users\arto\Desktop\keyboard_test\keyboard_test
Step 3 — Run menuconfig
Type the following command:
idf.py menuconfig
This will open the ESP-IDF configuration interface.
Step 4 — Enter Component Config
Inside the menu, select:
Component config
Step 5 — Open LVGL Configuration
Scroll down and choose:
LVGL configuration
Step 6 — Go to Font Usage
Select:
Font usage
Step 7 — Disable Custom Font
Scroll down until you find:
Enable the custom font
Make sure it is unchecked.
If this option is enabled, ESP-IDF generates:
CONFIG_LV_FONT_CUSTOM_DECLARE=""
disable like this :
Step 8 — Save Configuration
Press:
S
To save the configuration.
Then exit menuconfig.
Step 9 — Clean and Rebuild
Run the following commands:
idf.py fullclean idf.py build
Why This Works
This error is caused by a Kconfig-generated macro:
#define CONFIG_LV_FONT_CUSTOM_DECLARE ""
By disabling custom font support, ESP-IDF stops generating the invalid macro, and the build system regenerates a valid sdkconfig.h.
Always fix configuration-layer errors at the configuration layer — not inside source files.
Read Also : How to add / register Waveshare ESP32-S3 7-inch board into SquareLine Studio as a custom board configuration
Gabung dalam percakapan