Skip to content

linker error app_main not found CONFIG_AUTOSTART_ARDUINO is not set (Blink.cpp example) #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iafilius opened this issue Aug 23, 2020 · 4 comments

Comments

@iafilius
Copy link

iafilius commented Aug 23, 2020

Hi,

Just started with the arduino as component (platformio) and working to get a previous
project to run, but ended up with the Blink.cpp sample from:
https://github.com/platformio/platform-espressif32/tree/master/examples/espidf-arduino-blink
for reproducing the issue.

The issue while building Blink.cpp gives a linker error:

Building in release mode
Compiling .pio/build/esp320/esp-idf/src/Blink.cpp.o
Linking .pio/build/esp320/firmware.elf
/home/arjan/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp320/esp-idf/esp32/libesp32.a(cpu_start.c.o):(.literal.main_task+0x18): u
/home/arjan/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp320/esp-idf/esp32/libesp32.a(cpu_start.c.o): in function `main_task':
/home/arjan/.platformio/packages/framework-espidf/components/esp32/cpu_start.c:539: undefined reference to `app_main'
collect2: error: ld returned 1 exit status
*** [.pio/build/esp320/firmware.elf] Error 1

In short i kept having linker errors where app_main is not found under conditions when :

  • sdkconfig:# CONFIG_AUTOSTART_ARDUINO is not set
    and and only and
  • if code has C++ extension (.cpp)

The solution for this is given on espressif/arduino-esp32#1840
to change the Blink.cpp example from:

void app_main()
{
initArduino();
...
}

to:

extern "C" void app_main()
{
initArduino();
...
}

As it was not part of the topic no fix to code was proposed. and i don't want to change topic/revive old issue, so created new issue.

Not sure if it is the best solution to the problem, but it makes the blink
sample compile after having CONFIG_AUTOSTART_ARDUINO unset.
The code seems to cope with both cases CONFIG_AUTOSTART_ARDUINO is set or not.

If agreed on solution, shall i create a pull request for it? (develop
branche i guess?)

Regards,

Arjan

@valeros
Copy link
Member

valeros commented Aug 25, 2020

Hi Arjan, thanks for the info.

sdkconfig:# CONFIG_AUTOSTART_ARDUINO is not set

Not sure if it is the best solution to the problem, but it makes the blink
sample compile after having CONFIG_AUTOSTART_ARDUINO unset.
The code seems to cope with both cases CONFIG_AUTOSTART_ARDUINO is set or not.

So what is the correct value? It's set to y here https://github.com/platformio/platform-espressif32/blob/develop/examples/espidf-arduino-blink/sdkconfig.defaults#L3

As for extern "C" void, looks like it should be added by default, so a PR is very welcomed.

@iafilius
Copy link
Author

Hi, i see in develop branch arduino as component blink.cpp sample the support for #if !CONFIG_AUTOSTART_ARDUINO completely has been removed, which would make a PR to fix it a bit silly i'm afraid.

@stale
Copy link

stale bot commented Jul 31, 2022

This issue has been automatically marked as stale because it has not had recent activity. Please provide more details or it will be closed if no further activity occurs. Thank you for your contributions.

1 similar comment
@stale
Copy link

stale bot commented Sep 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. Please provide more details or it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 8, 2022
@stale stale bot closed this as completed Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants