Programming in C++

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: Programming in C++

Postby mzimmers » Tue Mar 27, 2018 1:40 am

I have three source files in my project.

MZimmers@mzimmers-w10p MSYS /c/esp32_projects/esp32_wifi/build/main
$ ls
component_project_vars.mk console.d console.o libmain.a main.d main.o socket.d socket.o
MZimmers@mzimmers-w10p MSYS /c/esp32_projects/esp32_wifi/build/main
$ xtensa-esp32-elf-nm main.o
U _esp_error_check_failed
U _Z10socketIniti
00000000 T _Z13event_handlerPvP14system_event_t
U _Z18initialize_consolev
U _Z8wifiInitv
00000000 r _ZZ13event_handlerPvP14system_event_tE19__PRETTY_FUNCTION__
00000000 r _ZZ8app_mainE19__PRETTY_FUNCTION__
00000000 T app_main
U esp_event_loop_init
U esp_wifi_scan_get_ap_records
U esp_wifi_scan_start
U free
U malloc
U memcpy
U nvs_flash_init
U printf
U tcpip_adapter_init

MZimmers@mzimmers-w10p MSYS /c/esp32_projects/esp32_wifi/build/main
$
~~~
Already tried deleting the entire build tree; no success with that.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Programming in C++

Postby kolban » Tue Mar 27, 2018 1:46 am

Can you post the exact error message being produced? Maybe try the make after setting the environment variable "V=1" to get more verbosity. Can you also paste-bin your main source file. It might be useful to have a fresh pair of eyes on the "app_main" declaration.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: Programming in C++

Postby mzimmers » Tue Mar 27, 2018 1:57 am

LD build/wifi_button.elf
C:/esp32_projects/esp32_wifi/build/esp32\libesp32.a(cpu_start.o):(.literal.main_task+0x20): undefined reference to `app_main'
C:/esp32_projects/esp32_wifi/build/esp32\libesp32.a(cpu_start.o): In function `main_task':
C:/esp-idf-v3.0-rc1/components/esp32/cpu_start.c:452: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
make: *** [c:/esp-idf-v3.0-rc1/make/project.mk:387: /c/esp32_projects/esp32_wifi/build/wifi_button.elf] Error 1

https://pastebin.com/YvuCp4d7

Thanks...

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Programming in C++

Postby kolban » Tue Mar 27, 2018 3:26 am

Hmmm .... well I'm puzzled. The "nm" command is showing a definition for a C function called "app_main" in the library as one would hope. Your C file looks good. However your report say that the linkage can't find "app_main". Thinking this through, what might remain is the notion that "somehow" your compilation is simply not including libmain.a. We might be able to determine that by your deleting build and then doing a build with an export of "V=1" and capturing the results and paste-bining them. That will show which files are being link-edited together to produce the resulting final binary. The reported story would be consistent with compiling main.cpp, adding it to the library but not including the library in the linkage.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Programming in C++

Postby chegewara » Tue Mar 27, 2018 1:23 pm

I am able to recrete similar error, but obviously its not you case, by removing extern "C" from main.cpp.
Attachments
app_main.JPG
app_main.JPG (49.05 KiB) Viewed 13218 times

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: Programming in C++

Postby mzimmers » Tue Mar 27, 2018 3:29 pm

DISREGARD THIS POST -- cockpit error. Somehow I invoked msys2.exe instead of mingw32.exe, and that caused this python issue to manifest. Still working on the original issue.


Hi Mr. Kolban - I seem to have taken a step back in this effort. My make is now terminating earlier than before, due to an error related to an attempt to invoke Python (which I really don't understand). I've done a make clean, and even deleted the build directory, and this error persists. Here's a fragment:

Code: Select all

python /c/esp-idf-v3.0-rc1/components/esptool_py/esptool/esptool.py --chip esp32 elf2image --flash_mode "dio" --flash_freq "40m" --flash_size "4MB"  -o /c/esp32_projects/esp32_wifi/build/bootloader/bootloader.bin /c/esp32_projects/esp32_wifi/build/bootloader/bootloader.elf
/bin/sh: python: command not found
make[1]: *** [/c/esp-idf-v3.0-rc1/components/esptool_py/Makefile.projbuild:51: /c/esp32_projects/esp32_wifi/build/bootloader/bootloader.bin] Error 127
make[1]: Leaving directory '/c/esp-idf-v3.0-rc1/components/bootloader/subproject'
Why is make trying to invoke a Python interpreter? Is there Python code somewhere in the build process?
Last edited by mzimmers on Tue Mar 27, 2018 4:21 pm, edited 1 time in total.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Programming in C++

Postby kolban » Tue Mar 27, 2018 3:41 pm

The build process in an ESP32 is ...

one or more C/C++ sources files get compiled to object files (.o)
sets of object files are archived together to create one or more libraries (.a)
the libraries and some additional objects are linked together to produce an executable ELF format file (.elf)
The ELF binary is "decomposed" into its "content sections" and grunged together into a simper format that is understood by the ESP32 bootloader (.bin)

Now that you have a bin, it can be pushed to flash into the ESP32.

The generation of the bin from the elf is performed by the esptool program ... which is written in Python ... and requires the Python runtime to be available.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: Programming in C++

Postby mzimmers » Tue Mar 27, 2018 4:23 pm

Hi Mr. Kolban - sorry for the red herring (explained above) and thanks for the information -- that's still useful. I'll get you the verbose build output shortly.
~~~
EDIT: my verbose build output exceeds the 512KB limit on pastebin. Here's the command that caused the error (I think):

Code: Select all

xtensa-esp32-elf-gcc -nostdlib -u call_user_start_cpu0  -Wl,--gc-sections -Wl,-static -Wl,--start-group  -L/c/esp32_projects/esp32_wifi/build/app_trace -lapp_trace -L/c/esp32_projects/esp32_wifi/build/app_update -lapp_update -L/c/esp32_projects/esp32_wifi/build/aws_iot  -L/c/esp32_projects/esp32_wifi/build/bootloader_support -lbootloader_support -L/c/esp32_projects/esp32_wifi/build/bt -lbt -L/c/esp32_projects/esp32_wifi/build/coap -lcoap -L/c/esp32_projects/esp32_wifi/build/console -lconsole -L/c/esp32_projects/esp32_wifi/build/cxx -lcxx -u __cxa_guard_dummy -u __cxx_fatal_exception -L/c/esp32_projects/esp32_wifi/build/driver -ldriver -L/c/esp32_projects/esp32_wifi/build/esp32 -lesp32 /c/esp-idf-v3.0-rc1/components/esp32/libhal.a -L/c/esp-idf-v3.0-rc1/components/esp32/lib -lcore -lrtc -lnet80211 -lpp -lwpa -lsmartconfig -lcoexist -lwps -lwpa2 -lespnow -lphy -L /c/esp-idf-v3.0-rc1/components/esp32/ld -T esp32_out.ld -u ld_include_panic_highint_hdl -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.spiram_incompatible_fns.ld -L/c/esp32_projects/esp32_wifi/build/esp_adc_cal -lesp_adc_cal -L/c/esp32_projects/esp32_wifi/build/ethernet -lethernet -L/c/esp32_projects/esp32_wifi/build/expat -lexpat -L/c/esp32_projects/esp32_wifi/build/fatfs -lfatfs -L/c/esp32_projects/esp32_wifi/build/freertos -lfreertos -Wl,--undefined=uxTopUsedPriority -L/c/esp32_projects/esp32_wifi/build/heap -lheap -L/c/esp32_projects/esp32_wifi/build/idf_test -lidf_test -L/c/esp32_projects/esp32_wifi/build/jsmn -ljsmn -L/c/esp32_projects/esp32_wifi/build/json -ljson -L/c/esp32_projects/esp32_wifi/build/libsodium -llibsodium -L/c/esp32_projects/esp32_wifi/build/log -llog -L/c/esp32_projects/esp32_wifi/build/lwip -llwip 


-L/c/esp32_projects/esp32_wifi/build/main -lstdc++ 


-L/c/esp32_projects/esp32_wifi/build/mbedtls -lmbedtls -L/c/esp32_projects/esp32_wifi/build/mdns -lmdns -L/c/esp32_projects/esp32_wifi/build/micro-ecc -lmicro-ecc -L/c/esp32_projects/esp32_wifi/build/newlib /c/esp-idf-v3.0-rc1/components/newlib/lib/libc.a /c/esp-idf-v3.0-rc1/components/newlib/lib/libm.a -lnewlib -L/c/esp32_projects/esp32_wifi/build/nghttp -lnghttp -L/c/esp32_projects/esp32_wifi/build/nvs_flash -lnvs_flash -L/c/esp32_projects/esp32_wifi/build/openssl -lopenssl -L/c/esp32_projects/esp32_wifi/build/pthread -lpthread -L/c/esp32_projects/esp32_wifi/build/sdmmc -lsdmmc -L/c/esp32_projects/esp32_wifi/build/soc -lsoc -L/c/esp32_projects/esp32_wifi/build/spi_flash -lspi_flash -L/c/esp32_projects/esp32_wifi/build/spiffs -lspiffs -L/c/esp32_projects/esp32_wifi/build/tcpip_adapter -ltcpip_adapter -L/c/esp32_projects/esp32_wifi/build/ulp -lulp -L/c/esp32_projects/esp32_wifi/build/vfs -lvfs -L/c/esp32_projects/esp32_wifi/build/wear_levelling -lwear_levelling -L/c/esp32_projects/esp32_wifi/build/wpa_supplicant -lwpa_supplicant -L/c/esp32_projects/esp32_wifi/build/xtensa-debug-module -lxtensa-debug-module -lgcc -lstdc++ -lgcov -Wl,--end-group -Wl,-EL -o /c/esp32_projects/esp32_wifi/build/wifi_button.elf -Wl,-Map=/c/esp32_projects/esp32_wifi/build/wifi_button.map
I separated the section dealing with main -- notice the oddity of the flags being confused for the filename (or vice versa). I'm fairly sure that's my issue, though I don't know what could be causing it.

EDIT 2: the offending line was in something I'd put in main/component.mk:

COMPONENT_ADD_LDFLAGS=-lstdc++

Removing this eliminated the error.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Programming in C++

Postby kolban » Tue Mar 27, 2018 6:09 pm

Great work. Thanks for posting back that you have the puzzle resolved.

Mr Kolban was my dad. Call me kolban, Neil or "dumbass" ... I'll answer to most about anything.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: Programming in C++

Postby mzimmers » Tue Mar 27, 2018 6:31 pm

Heh...fair enough, Neil. That line:

COMPONENT_ADD_LDFLAGS=-lstdc++

in the component.mk file was something I got from your very first post in this thread...did I misuse or malform it somehow?

Who is online

Users browsing this forum: Bing [Bot], MicroController and 198 guests