M5Stack, ESP32 linking error: collect2.exe: error: ld returned 1 exit status

Hello, I just started a new job where I’m supposed to continue working on a code base from someone who is not in the company anymore.

The firmware is for an ESP32 in an M5Stack, and includes AWS FreeRTOS for some IoT features.

I am trying to get the code to compile at all, but I’m having trouble already. I have installed the ESP32 framework

After running platformio run, PlatformIO spends a bit of time compiling lots of files. then after it’s done compiling it fails with this error.

Archiving .pio\build\m5stack-core-esp32\bootloader\esp-idf\log\liblog.a
Linking .pio\build\m5stack-core-esp32\bootloader.elf
Building .pio\build\m5stack-core-esp32\bootloader.bin
esptool.py v2.6
Linking .pio\build\m5stack-core-esp32\firmware.elf
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\aws-root-ca.pem.S.o: in function `aws_root_ca_pem':
(.rodata.embedded+0x0): multiple definition of `aws_root_ca_pem'; .pio\build\m5stack-core-esp32\aws-root-ca.pem.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\aws-root-ca.pem.S.o: in function `aws_root_ca_pem':
(.rodata.embedded+0x0): multiple definition of `_binary_aws_root_ca_pem_start'; .pio\build\m5stack-core-esp32\aws-root-ca.pem.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\aws-root-ca.pem.S.o: in function `_binary_aws_root_ca_pem_end':
(.rodata.embedded+0x4a5): multiple definition of `_binary_aws_root_ca_pem_end'; .pio\build\m5stack-core-esp32\aws-root-ca.pem.o:(.rodata.embedded+0x4a5): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\aws-root-ca.pem.S.o: in function `_binary_aws_root_ca_pem_end':
(.rodata.embedded+0x4a5): multiple definition of `aws_root_ca_pem_length'; .pio\build\m5stack-core-esp32\aws-root-ca.pem.o:(.rodata.embedded+0x4a5): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\certificate.pem.crt.S.o: in function `certificate_pem_crt':
(.rodata.embedded+0x0): multiple definition of `certificate_pem_crt'; .pio\build\m5stack-core-esp32\certificate.pem.crt.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\certificate.pem.crt.S.o: in function `certificate_pem_crt':
(.rodata.embedded+0x0): multiple definition of `_binary_certificate_pem_crt_start'; .pio\build\m5stack-core-esp32\certificate.pem.crt.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\certificate.pem.crt.S.o: in function `_binary_certificate_pem_crt_end':
(.rodata.embedded+0x4c8): multiple definition of `_binary_certificate_pem_crt_end'; .pio\build\m5stack-core-esp32\certificate.pem.crt.o:(.rodata.embedded+0x4c8): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\certificate.pem.crt.S.o: in function `_binary_certificate_pem_crt_end':
(.rodata.embedded+0x4c8): multiple definition of `certificate_pem_crt_length'; .pio\build\m5stack-core-esp32\certificate.pem.crt.o:(.rodata.embedded+0x4c8): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\private.pem.key.S.o: in function `private_pem_key':
(.rodata.embedded+0x0): multiple definition of `private_pem_key'; .pio\build\m5stack-core-esp32\private.pem.key.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\private.pem.key.S.o: in function `private_pem_key':
(.rodata.embedded+0x0): multiple definition of `_binary_private_pem_key_start'; .pio\build\m5stack-core-esp32\private.pem.key.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\private.pem.key.S.o: in function `_binary_private_pem_key_end':
(.rodata.embedded+0x690): multiple definition of `_binary_private_pem_key_end'; .pio\build\m5stack-core-esp32\private.pem.key.o:(.rodata.embedded+0x690): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\private.pem.key.S.o: in function `_binary_private_pem_key_end':
(.rodata.embedded+0x690): multiple definition of `private_pem_key_length'; .pio\build\m5stack-core-esp32\private.pem.key.o:(.rodata.embedded+0x690): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.S.o: in function `e59ed86b90_private_pem_key':
(.rodata.embedded+0x0): multiple definition of `e59ed86b90_private_pem_key'; .pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.S.o: in function `e59ed86b90_private_pem_key':
(.rodata.embedded+0x0): multiple definition of `_binary_e59ed86b90_private_pem_key_start'; .pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.o:(.rodata.embedded+0x0): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.S.o: in function `_binary_e59ed86b90_private_pem_key_end':
(.rodata.embedded+0x68c): multiple definition of `_binary_e59ed86b90_private_pem_key_end'; .pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.o:(.rodata.embedded+0x68c): first defined here
c:/users/andrew/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\m5stack-core-esp32\esp-idf\.pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.S.o: in function `_binary_e59ed86b90_private_pem_key_end':
(.rodata.embedded+0x68c): multiple definition of `e59ed86b90_private_pem_key_length'; .pio\build\m5stack-core-esp32\e59ed86b90-private.pem.key.o:(.rodata.embedded+0x68c): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\m5stack-core-esp32\firmware.elf] Error 1
=============================================================================================================================================== [FAILED] Took 358.75 seconds ===============================================================================================================================================PS C:\Users\andrew\Documents\esim-m2m-demo-master@c8fcb79c644> 

Could anyone point me to where the problem could be? I’m quite a beginner, so I’m not even sure if that multiple definitions warning is enough to cause a linking error. Is there anywhere else I could look to figure out why the linker isn’t working?

Thank you!

As the error message tells you: Two object files (derived from .c files or directly created) are conflicting since both want to define the same symbol. You have the certificate.pem.crt.o wanting to define the symbol _binary_certificate_pem_crt_start and at the same time certificate.pem.crt.S.o.

This might be a core bug in PlatformIO that these two files are created in a duplicate manner. You may try and use different platform = espressif32@<version> settings in regards to Releases · platformio/platform-espressif32 · GitHub if the bug was introduced recently. e,g, espressif32@2.0.0 and espressif32@1.12.4.

Oh my God, it worked! Thank you so much!!! Seems to a bug from the recent update. I was able to compile using 1.12.0

Sure that 1.12.4 doesn’t work either? Going back to 1.12.0 also implies a different ESP-IDF version (v4.0 for 1.12.0, starting at 1.12.2 ESP-IDF v4.0.1, starting at 2.0.0 ESP-IDF v4.1), so be very careful with that, as there are very likely breaking API changes. It’s best to pin the platform version that is being developed against with @version, as per docs.

On a different note, can you clone the repo and example at platform-espressif32/examples/espidf-aws-iot at develop · platformio/platform-espressif32 · GitHub and try a normal compile, with the platform explicitly set to espressif32@2.0.0? Does this compile for you?

Sorry for taking so long to reply. There was a whole lot to figure out about this code base so it took me a long time to figure what was actually wrong here. It turns out, since Espressif32 2.0 you can embed binary files (in this case aws certificates) just using platformio.ini

Before one also had to add them to the Cmake file. Since this project was older, it had both so it caused a multiple definition error. Removing the lines in the cmake file in the src folder fixed the problem and allowed me to use the new idf version.

1 Like