Testing use of pre-compiled library. I'm getting an "undefined reference" error. The .a file was created in ESP-IDF as a test case. Eventually I need to create a class there because of some issues with the USB-HOST support for an ESP32-S3.
It seems that the Arduino build system is finding your header fine, but it’s not actually linking your libHello.a into the final binary, which is why you would get the “undefined reference” errors.
Did you call the library libHello.a ?
Is it in the right place ? I think it has to live inside src/ in your library folder: libraries/Hello/src/libHello.a and how did you compile it (did you target the S3?)
Thank you both. The compile did target the S3 and name is libHello.a. I've tried placing a copy at every level I could find any references to in my private library and the one in \arduino15\libraries.
C:\dev\SKETCHBOOK\libraries\ **Hello** >tree
Folder PATH listing for volume Windows
Volume serial number is 34E4-1A1F
C:.
└───src
└───esp32
└───esp32s3
C:/Users/Chuck/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2411/bin/../lib/gcc/xt
C:\dev\SKETCHBOOK\Precompile_test/Precompile_test.ino:4:(.text._Z5setupv+0x6): undefined r
C:/Users/Chuck/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2411/bin/../lib/gcc/xt
**collect2.exe: error: ld returned 1 exit status**
Multiple libraries were found for "Hello.h"
Used: C:\dev\SKETCHBOOK\libraries\Hello
Not used: C:\Users\Chuck\AppData\Local\Arduino15\libraries\Hello
**Using library Hello in folder: C:\dev\SKETCHBOOK\libraries\Hello (legacy)**
I interpret this to mean that the linker is finding the correct library but having finding the actual .a file, or finding the file and not finding the class declaration in the... we used to call it symbol table, in the object module.
Maybe it's some kind of extern / name-mangling thing? I guess I could try and find a way to dump the object module, but that's something I haven't done since the 60's on s/360 systems! I did run an ar command and it shows the .o file is in the "archive".
Update ---- I tried deleting the .a file and I get exactly the same messages, so it seems the loader really isn't finding it and not a problem with its contents.
Seems OK. But, per last experiment, I don't think it's ever finding it to process.
C:\dev\SKETCHBOOK\libraries\Hello>xtensa-esp32s3-elf-nm libHello.a | grep Hello
Hello.cpp.obj:
00000000 T _ZN5Hello8sayHelloEv
00000000 T _ZN5HelloC1Ev
00000000 T _ZN5HelloC2Ev
Yes - that confirms your archive is fine. The symbols like _ZN5HelloC1Ev and _ZN5Hello8sayHelloEv are the mangled names for Hello::Hello() and Hello::sayHello() , and the T indicates they are defined in the text section.
You should try next the layout - may be it's just that...
Tried your suggestion - getting closer. Can't quite figure out this message.
C:/Users/Chuck/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2411/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: cannot find C:\Users\Chuck\AppData\Local\arduino\sketches\994B45CE06D93F6B3F616DE99D8489C4\libraries\Hello\Hello.a: No such file or directory
Tried with and without the linker flags - same result.
Then a src folder containing Hello.h ➜ the header needed by your sketch
then a subdirectory esp32 in which you have libHello.a ➜ the precompiled library compiled for the ESP32 architecture
Except for sketchbook location, I think it's what you suggested. Copying the .a made no difference. This is going to be something really stupid I've done.... thanks for staying with me.
Bingo! I changed the directory to esp32s3 and it worked! Apparently it has to be the exact name as in the boards.txt file. I'm not getting any output, but that's a new battle.
Thank you very much for working with me. I'd been fighting this for 3 days and desperately needed the focus you supplied.
Adding word wrap and an additional indent to the very long linker command will make it easier to see the paths and files. (Don't know what the equivalent of sed is on Windows)
Thanks for that. I'm getting a new appreciation for the complexity of build systems now that I've worked with Arduino, PlatformIO, and ESP-IDF. So hard to grok messages with the ridiculously long paths.