micro/examples/rp2350: Build failure: Undefined reference to __dso_handle during linking
I used Google AI Mode to run down this problem and at the end I said: "Please generate a summary of this fix so I can open a GitHub issue to share with other people"
Bug Description
When compiling the Moonshine Micro project for the RP2350 (Pico 2) target architecture using the specific arm-none-eabi-gcc 13.3.1 toolchain, the final linking stage fails with linker errors.
The compiler pulls in hooks for dynamic shared object destruction that do not exist natively in the bare-metal runtime environment. Attempting to bypass this by globally enabling C++ exceptions (PICO_CXX_ENABLE_EXCEPTIONS) shifts the failure into TensorFlow Lite Micro, breaking its custom embedded memory layout.
Terminal Error Output
/arm-none-eabi/bin/ld: ../../g2p/libg2p.a(g2p_rules.cc.o): in function `g2p::(anonymous namespace)::FunctionWords() [clone .part.0]':
g2p_rules.cc:(.text): undefined reference to `__dso_handle'
/arm-none-eabi/bin/ld: moonshine_micro_echo.elf: hidden symbol `__dso_handle' isn't defined
collect2: error: ld returned 1 exit statusRoot Cause
The __dso_handle and _fini symbols are automatically referenced by static initializers and portions of the pre-compiled libstdc++.a library. Because the target build is bare-metal, these runtime anchors are missing, causing the linker stage to fail on downstream binaries.
Solution
Provide explicit global fallback stub symbols at the absolute top of the CMake configuration pipeline. This allows all downstream executables and libraries (libg2p.a, example binaries) to cleanly share the runtime symbol definition.
Add this code snippet to the top-level CMakeLists.txt file, immediately following the project() initialization statement:
# Fix for undefined reference to __dso_handle in bare-metal arm-none-eabi toolchains
if(NOT TARGET toolchain_stubs)
file(WRITE "\${CMAKE_BINARY_DIR}/toolchain_stubs.c" "void* __dso_handle = 0;\nvoid* _fini = 0;\n")
add_library(toolchain_stubs STATIC "\${CMAKE_BINARY_DIR}/toolchain_stubs.c")
endif()
# Bind stubs globally to all targets
link_libraries(toolchain_stubs)Once the file is updated, flush the cache and execute a clean build:
rm -rf build/
examples/rp2350/scripts/build.shSource: moonshine-ai/moonshine