Include external fonts for the LVGL library


We work with the LVGL library. That works great, but we also have additional fonts that we use, stored in a top level folder. But the LVGL library just can’t find them. We work with these build flags:

lvgl_build_flags = 
    -I fonts
    -I include

The -I include is for the lvgl config file, managed in the include folder. This works fine in combination with the LV_CONF_INCLUDE_SIMPLE tag. But to use the fonts we now have to copy them manually to the /lipdeps/environment/lvgl/src/lv_font folder. But we have to do that for each environment.

I also created a topic on the LVGL forums as it might be an issue with the LVGL library.

Any suggestions are welcome!

Just thinking out loud, if it’s too hard to include the files form the fonts folder, would it be possible to use a script to copy the fonts to the /lipdeps/environment/lvgl/src/lv_font before compiling?

Hi David,

Normally (e.g. from main.c) how do you include lvgl.h?

The fonts want to include lvgl.h like this:

  #include "lvgl.h"
  #include "lvgl/lvgl.h"

So if you add -D LV_LVGL_H_INCLUDE_SIMPLE the fonts will attempt to #include "lvgl.h".

Hi Gabor,

I’ve tried that, also with just changing it to

#include "lvgl.h" 

To be sure nothing’s wrong with the build flag but that doens’t work… Here’s our file structure:

What is the exact error message? Could you copy it here?

I’m not a PlatformIO expert, but are sure PlatformIO builds the files outside of the src folder too?

Hi Gabor,

This is the warning:

I think it’ll be easier to just copy the files to the lib_deps folder using a Python script. But I’m looking for an example code. Maybe @ivankravets knows an example?


The undefined reference error is expected since files on <root>/fonts are not compiled. Only sources in src/, lib/<library name> or .pio/libdeps/<env>/<lib name> are.

You might be able to use a side-effect of the build_src_filter platformio.ini options to add the file to the to-be-compiled files, by doing

build_src_filter = +<../fonts/*.c>

Otherwise you can do a quick test that if the file is in src/, the error is resolevd.


Hi Max,

That’s something I tried, I tried both the src and the include folder and manually tried both flags as well: #include “lvgl/lvgl.h” and #include “lvgl.h”. But still no solution.

Both my collegue and I have tried a lot of combo’s in the past, but non of them worked, so we’re used to coping the files to the lib_deps for now. But this now blocks our next step where we would like to use github actions to automatically build the binfiles on release.

Have you tried to copy “fonts” to the “src” folder?

Yes I tried that as well. I probably have to create a basic project that I can easily share.


So I went for the other way. I just copy our custom fonts to the library using a python script like this:

def add_custom_fonts():
    # Specify path
    print("root: " +os.getcwd()) #root: /Users/davidtsqr/Source/cufw

    # Check whether the specified
    # path exists or not
    srcPath =os.getcwd()+"/fonts/customfonts"
    targetPath = os.getcwd()+"/.pio/libdeps/" + env["PIOENV"] + "/lvgl/src/lv_font/customfonts"
    srcExists = os.path.exists(srcPath)
    print(srcPath, " exists: ", srcExists)
    targetExists = os.path.exists(targetPath)
    if not targetExists:

Works like a charm!!! We now can clone and build. Awesome. Next stop Github Actions :slight_smile:

Have you tried to add fonts to the src folder? It seems this is the valid place because C/C++ files from the “fonts” are part of a build process.

Hi Ivan,

I’ve tried all those things. I’ve added them to the src folder with the different #include statements (both #include “lvgl.h” or #include “lvgl/lvgl.h”. Same with the include folder. But that all didn’t work…

Probably I’m doing something wrong, but I’ve spent too much time on this so I’ll stick to the solution I have for now.

Could you provide a bare project that uses custom fonts and your “copy script”? I’ll try to debug it myself. You can pack it as ZIP and attach to this issue.

Hi David,

Sorry for the delay. I’ve finally experimented with LVGL + external fonts located outside the project source directory. See below what I learned:

  1. PlatformIO allows adding external C/C++ files located outside the project’s source folder to the build process. See more details at Build external sources — PlatformIO latest documentation. However, this approach will not work for your case because the custom LVGL fonts depend on the LVGL library.
  2. Moving custom fonts including C sources to a project’s private lib folder is the right solution and it works out of the box. I created a folder named lvgl-fonts with custom fonts that use #include <lvgl.h> and put it in the project/lib folder. Next, I added lvgl-fonts to the lib_deps in the platformio.ini:
lib_deps =

It works for me. Could you try the 2nd approach?

That trick seems to work perfectly! Never thought of using lib_deps to include a local lib… And why don’t I have to do that for the other libs? Anyway, I’ll do some more research tomorrow.

Thx a lot :+1:

1 Like

Hi I am using platformio extension for vscode and my error is that LVGL not found the lv_conf.h
¿Do you know how to fix that issue or error?
I saw that maybe whith this build flag it will work:-DLV_CONF_INCLUDE_SIMPLE
but don’t

lib/ is not in the include path by default. You should just move the lv_conf.h file to the include/ folder (which you also deleted?). If libraries (and not only files in the src/ folder) need to see this file, add build_flags = -I include in the platformio.ini too.