Hi,
I hope this hasn't been answered before. I tried to search the forum but the page timed out before I got any results. Anyway...
I have a third-party library developed with autotools instead of CMake. I was able to successfully configure and build it with the xtensa-esp32 toolset that comes along with ESP-IDF. Now, for the life of me, I can't figure out how to get it linked in with the rest of my main IDF project. It seems like such a simple goal: an additional .a file included in the linker command. But I've tried everything I can think of and it always winds up in one of two places: Either CMake fails to finish generating the build scripts, or the link fails with undefined symbols. So let's say I have, in my "components" directory, a directory called "freetype" which contains all the relevant headers, and a static library file libfreetype.a. How do I get that fed into the linker under the ESP-IDF system?
If you're wondering why I'd even bother trying to link FreeType into my ESP32 project... My project includes a small graphical OLED display which communicates over SPI. At the hardware level, I've got that all working perfectly. But that display driver doesn't have a character ROM; it's purely graphical. I thought I might try using FreeType to handle rendering characters, and embed a .ttf font in the binary. Embedding stuff is easy (EMBED just works).
Anyway, thanks!
Link an external static object archive (.a)
Re: Link an external static object archive (.a)
So, after banging my head against it for more hours today, I finally got it working. Here's the magic:
In components/freetype is libfreetype.a and a CMakeLists.txt which only contains this:
(yep, no arguments)
In the component that depends on it, this is its CMakeLists.txt:
So the magic is that after the "idf_component_register" call, you can put in commands that otherwise would cause "command is not scriptable" errors from CMake.
I hope this helps someone else!
In components/freetype is libfreetype.a and a CMakeLists.txt which only contains this:
Code: Select all
idf_component_register()
In the component that depends on it, this is its CMakeLists.txt:
Code: Select all
idf_component_register(SRCS "resource.cpp" "font.cpp"
INCLUDE_DIRS "../freetype/include/"
INCLUDE_DIRS "../"
EMBED_FILES "myfont.ttf"
)
add_library(freetype STATIC IMPORTED GLOBAL)
set_property(TARGET freetype PROPERTY IMPORTED_LOCATION "${COMPONENT_DIR}/../freetype/libfreetype.a")
target_link_libraries(${COMPONENT_TARGET} PUBLIC freetype)
I hope this helps someone else!
- shabtronic
- Posts: 49
- Joined: Sun Nov 03, 2019 1:33 pm
Re: Link an external static object archive (.a)
Cool stuff dude - I had major problems linking in embedded binaries - so much so I gave up lol
Thanks for sharing the knowledge!
Thanks for sharing the knowledge!
Re: Link an external static object archive (.a)
FWIW, this is the correct answer:
https://esp32.com/viewtopic.php?t=16452
I just followed these instructions, and I was able to build a Hello World app while pulling a couple of functions from my application libraries. Here's the CMakeLists.txt for the component:
So in my component directory, I have the above CMake file, a "lib" subdirectory containing my app libraries archive, and an "include" directory containing all the relevant include files for my library. Works great.
https://esp32.com/viewtopic.php?t=16452
I just followed these instructions, and I was able to build a Hello World app while pulling a couple of functions from my application libraries. Here's the CMakeLists.txt for the component:
Code: Select all
# App libs include component w/ prebuilt source library.
# Set this to whatever components your library requires.
set (APPLIBS_REQUIRES freertos driver nvs_flash spi_flash esp_hw_support esp_wifi esp_adc)
idf_component_register(SRCS ""
INCLUDE_DIRS "include"
REQUIRES ${APPLIBS_REQUIRES})
add_prebuilt_library(applibs_source "lib/libapplibs_source.a"
REQUIRES ${APPLIBS_REQUIRES})
target_link_libraries(${COMPONENT_LIB} INTERFACE applibs_source)
Who is online
Users browsing this forum: grantb and 64 guests