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
-D LV_CONF_INCLUDE_SIMPLE
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.
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?
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_filterplatformio.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.
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.
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.
Sorry for the delay. I’ve finally experimented with LVGL + external fonts located outside the project source directory. See below what I learned:
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.
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:
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.
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.