Skip to content

Commit cf6ab9c

Browse files
authored
component: Remove circular dependency around 'main' (#5391)
arduino-esp32 has to depend on main in autostart mode, for setup() and loop(), but this can be done with undefined symbol entries to avoid a large dependency cycle and other linker errors. Closes espressif/esp-idf#6968
1 parent 676f5cf commit cf6ab9c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: CMakeLists.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ set(includedirs
161161
set(srcs ${CORE_SRCS} ${LIBRARY_SRCS} ${BLE_SRCS})
162162
set(priv_includes cores/esp32/libb64)
163163
set(requires spi_flash mbedtls mdns esp_adc_cal wifi_provisioning nghttp)
164-
set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl bt main)
164+
set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl bt esp_ipc)
165165

166166
if(IDF_TARGET MATCHES "esp32s2|esp32s3" AND CONFIG_TINYUSB_ENABLED)
167167
list(APPEND priv_requires arduino_tinyusb)
@@ -183,3 +183,15 @@ endif()
183183
if(IDF_TARGET STREQUAL "esp32s2")
184184
target_compile_options(${COMPONENT_TARGET} PUBLIC -DARDUINO=10812 -DARDUINO_ESP32S2_DEV -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="ESP32S2_DEV" -DARDUINO_VARIANT="esp32s2" -DESP32)
185185
endif()
186+
187+
if(CONFIG_AUTOSTART_ARDUINO)
188+
# in autostart mode, arduino-esp32 contains app_main() function and needs to
189+
# reference setup() and loop() in the main component. If we add main
190+
# component to priv_requires then we create a large circular dependency
191+
# (arduino-esp32 -> main -> arduino-esp32) and can get linker errors, so
192+
# instead we add setup() and loop() to the undefined symbols list so the
193+
# linker will always include them.
194+
#
195+
# (As they are C++ symbol, we need to add the C++ mangled names.)
196+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u _Z5setupv -u _Z4loopv")
197+
endif()

0 commit comments

Comments
 (0)