question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

undefined reference to `app_main'

See original GitHub issue

OS : macOS 10.11.6 PlatformIO: 1.7.1(IDE), 3.2.1(Core)

use espidf-hello-world example, then come error below(I can use Arduino example normally):

Indexing .pioenvs/esp32dev/libtcpip_adapter.a
Linking .pioenvs/esp32dev/firmware.elf
.pioenvs/esp32dev/libesp32.a(cpu_start.o):(.literal.main_task+0x0): undefined reference to `app_main'
.pioenvs/esp32dev/libesp32.a(cpu_start.o): In function `main_task':
/Users/linjinhui/.platformio/packages/framework-espidf/components/esp32/cpu_start.c:169: undefined reference to `app_main'
collect2: error: ld returned 1 exit status
*** [.pioenvs/esp32dev/firmware.elf] Error 1

========================== [ERROR] Took 15.54 seconds ==========================

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
mintisancommented, Jan 13, 2017

should add extern "C" in front of app_main

/* Hello World Example
   This example code is in the Public Domain (or CC0 licensed, at your option.)
   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
 */
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"

void hello_task(void *pvParameter)
{
        printf("Hello world!\n");
        for (int i = 10; i >= 0; i--) {
                printf("Restarting in %d seconds...\n", i);
                vTaskDelay(1000 / portTICK_RATE_MS);
        }
        printf("Restarting now.\n");
        fflush(stdout);
        system_restart();
}

extern "C" void app_main()
{
        nvs_flash_init();
        system_init();
        xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL);
}

1reaction
derasdcommented, Sep 27, 2018

I had this error when I switched from compiling with platformio (vscode) to compiling with mingw32. The problem was that I had the code in the ./src folder instead of the ./main folder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

undefined reference to `app_main' - ESP32 Forum
Re: undefined reference to `app_main'​​ I have the exact same issue and I am not using CPP file.
Read more >
error:undefined reference to `app_main' · Issue #899 - GitHub
the main problem is undefined reference to `app_main' and I also refer to another same problem whose cause is not copying the component.mk...
Read more >
How to fix ESP-IDF 'undefined reference to app_main'
How to fix ESP-IDF 'undefined reference to app_main'. Problem: You are trying to compile your C/C++ ESP8266/ESP32 firmware using the ESP-IDF ...
Read more >
ESP32 & freertos & port_common.o & undefined reference to ...
Hello,. When i link my program, i have this error : (i have a main.cpp with an entry named void app_main()).
Read more >
undefined reference to _app_main - Stack Overflow
As the first error is a "Multiple definition of main" you must decide first which of the 2 main function you have is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found