libconsole.a not being included in my app - LD 'undefined reference' issues

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

libconsole.a not being included in my app - LD 'undefined reference' issues

Postby JeffWilliams » Sat Jan 27, 2018 4:29 pm

Hello,

I am running out of ideas other than digging deeper into the IDF make system. The examples/system/console example compiles just fine and works. I want to add a command system to a project I am building to allow for turning on/off modules at runtime. I have followed pattern of the example but I I get 'undefined reference' to the esp console API:

Code: Select all

LD build/TrackDAQ.elf
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds12taskCommandsEPv+0x18): undefined reference to `esp_console_run(char const*, int*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds22register_enableLoggersEv+0x18): undefined reference to `esp_console_cmd_register(esp_console_cmd_t const*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0xc): undefined reference to `esp_console_get_completion(char const*, linenoiseCompletions*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0x10): undefined reference to `esp_console_get_hint(char const*, int*, int*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0x18): undefined reference to `esp_console_init(esp_console_config_t const*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0x2c): undefined reference to `esp_console_register_help_command()'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o): In function `ControlCmds::taskCommands(void*)':
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/main/ControlCmds.cpp:107: undefined reference to `esp_console_run(char const*, int*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o): In function `ControlCmds::register_enableLoggers()':
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/main/ControlCmds.cpp:107: undefined reference to `esp_console_cmd_register(esp_console_cmd_t const*)'
I know it's libconsole.a I need included and I can see this being done for the example. Notice the last line where the make system checks the Prereq of libconsole.a for the app.elf

Code: Select all

$ make -d | grep libconsole
        Considering target file '/c/dev/esp-idf/examples/system/console/build/console/libconsole.a'.
  Considering target file 'libconsole.a'.
   Finished prerequisites of target file 'libconsole.a'.
   Prerequisite 'linenoise/linenoise.o' is older than target 'libconsole.a'.
   Prerequisite 'argtable3/argtable3.o' is older than target 'libconsole.a'.
   Prerequisite 'commands.o' is older than target 'libconsole.a'.
   Prerequisite 'split_argv.o' is older than target 'libconsole.a'.
  No need to remake target 'libconsole.a'.
         Finished prerequisites of target file '/c/dev/esp-idf/examples/system/console/build/console/libconsole.a'.
         Prerequisite 'component-console-build' of target '/c/dev/esp-idf/examples/system/console/build/console/libconsole.a' does not exist.
        Must remake target '/c/dev/esp-idf/examples/system/console/build/console/libconsole.a'.
Putting child 0x2008a838 (/c/dev/esp-idf/examples/system/console/build/console/libconsole.a) PID 8164 on the chain.
Live child 0x2008a838 (/c/dev/esp-idf/examples/system/console/build/console/libconsole.a) PID 8164
        Successfully remade target file '/c/dev/esp-idf/examples/system/console/build/console/libconsole.a'.
       Prerequisite '/c/dev/esp-idf/examples/system/console/build/console/libconsole.a' is older than target '/c/dev/esp-idf/examples/system/console/build/console.elf'.
The same results do not happen for my apps, it seems to compile libconsole.a but then doesn't seem to be including it in the elf image. I don't get the line " Prerequisite '......./libconsole.a' is older than target '......./TrackDAQ.elf' "

Code: Select all

$ make -d | grep libconsole
        Considering target file '/d/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/console/libconsole.a'.
  Considering target file 'libconsole.a'.
   Finished prerequisites of target file 'libconsole.a'.
   Prerequisite 'linenoise/linenoise.o' is older than target 'libconsole.a'.
   Prerequisite 'argtable3/argtable3.o' is older than target 'libconsole.a'.
   Prerequisite 'commands.o' is older than target 'libconsole.a'.
   Prerequisite 'split_argv.o' is older than target 'libconsole.a'.
  No need to remake target 'libconsole.a'.
         Finished prerequisites of target file '/d/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/console/libconsole.a'.
         Prerequisite 'component-console-build' of target '/d/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/console/libconsole.a' does not exist.
        Must remake target '/d/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/console/libconsole.a'.
Putting child 0x2008e5c0 (/d/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/console/libconsole.a) PID 5368 on the chain.
Live child 0x2008e5c0 (/d/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/console/libconsole.a) PID 5368
        Successfully remade target file '/d/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/console/libconsole.a'.
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds12taskCommandsEPv+0x18): undefined reference to `esp_console_run(char const*, int*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds22register_enableLoggersEv+0x18): undefined reference to `esp_console_cmd_register(esp_console_cmd_t const*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0xc): undefined reference to `esp_console_get_completion(char const*, linenoiseCompletions*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0x10): undefined reference to `esp_console_get_hint(char const*, int*, int*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0x18): undefined reference to `esp_console_init(esp_console_config_t const*)'
D:/dev/projects/motorcycle/TrackDAQ/TrackDAQ/build/main\libmain.a(ControlCmds.o):(.literal._ZN11ControlCmds5setupEv+0x2c): undefined reference to `esp_console_register_help_command()'

Anyone include the console APIs in their code and have issues? What am I missing?

Thanks, Jeff

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

Re: libconsole.a not being included in my app - LD 'undefined reference' issues

Postby chegewara » Sat Jan 27, 2018 5:32 pm

Considering target file 'libconsole.a'.
Finished prerequisites of target file 'libconsole.a'.
Prerequisite 'linenoise/linenoise.o' is older than target 'libconsole.a'.
Prerequisite 'argtable3/argtable3.o' is older than target 'libconsole.a'.
Prerequisite 'commands.o' is older than target 'libconsole.a'.
Prerequisite 'split_argv.o' is older than target 'libconsole.a'.
Update esp-idf and use command

Code: Select all

make clean

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

Re: libconsole.a not being included in my app - LD 'undefined reference' issues

Postby JeffWilliams » Sat Jan 27, 2018 6:10 pm

Hello,

I am using the latest IDF as of last night.
I have done make clean about 3 times

But I think I figured it out. I am using IDF + Arduino in the same project. I bet Arduino has a libconsole as well. Looking into it now...

Jeff

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: libconsole.a not being included in my app - LD 'undefined reference' issues

Postby ESP_Angus » Mon Jan 29, 2018 1:20 am

I think the issue is not actually the build system, but that esp_console.h is missing the 'extern "C"' guard around its declarations. So your C++ code is looking for C++ symbol names in the library, and failing to find them.

We will fix this in IDF ASAP, but a workaround is - in any C++ code you have which includes esp_console.h - change it to look like this:

Code: Select all

extern "C" {
#include "esp_console.h"
}
The workaround can be kept even after the root cause is fixed, it won't cause any problems.


Angus

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

Re: libconsole.a not being included in my app - LD 'undefined reference' issues

Postby JeffWilliams » Mon Jan 29, 2018 2:33 am

Hello,

Thanks Angus, that resolved it. I started to dig deeper into other things and then gave up on the console as really it's just a nice to have right now. Since everything else I have used in IDF already had the extern I never thought about that

Thanks, Jeff

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 75 guests