ESP8266 compile error. collect2.exe: error: ld returned 1 exit status

Hi, I am new to PIO and are migrating from Arduino IDE mostly because the debug feature that was recently made available.

I imported a project I need to debug from Arduino IDE where it compiles and runs successfully.

When I compile the sketch it produces the following error that I just have no idea where to look.

collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp01\firmware.elf] Error 1

Sketch code and library have been uploaded to:

https://drive.google.com/drive/folders/15iRMs8FYZ4L5KhsqqjQx2w1iBhZ7ybJf?usp=sharing

I also tried another project, this time ESP32 based, but have the exact same problem.

A simple blink test works perfectly with my debug hardware.

Thanks in advance.
Paulo

What’s the error before that? This just says “Linking failed :frowning: .”

What’s the platformio.ini file? The google drive does not contain the complete project structure.

Hi Max, thanks for your cooperation.

I have posted a zip file to the same Google Drive link with the entire project folder.
Hope everything is there now.

When I build there are 5 warnings:

4 of this type:

{
“resource”: “/c:/Users/pctbo/OneDrive/Documents/PlatformIO/Projects/190723-160653-esp01/src/CoapServerEsp8266.cpp”,
“owner”: “cpp”,
“severity”: 4,
“message”: “converting to non-pointer type ‘char’ from NULL [-Wconversion-null]”,
“startLineNumber”: 33,
“startColumn”: 25,
“endLineNumber”: 33,
“endColumn”: 25
}

And 1 of this type:

{
“resource”: “/c:/Users/pctbo/OneDrive/Documents/PlatformIO/Projects/190723-160653-esp01/src/CoapServerEsp8266.cpp”,
“owner”: “cpp”,
“severity”: 4,
“message”: “comparison between signed and unsigned integer expressions [-Wsign-compare]”,
“startLineNumber”: 152,
“startColumn”: 29,
“endLineNumber”: 152,
“endColumn”: 29
}

Then the error reported.

But Arduino IDE works well with those ( I did not even know these were problems).

Thanks in advance

Paulo Borges

I looked at the ZIP you posted and the compilation yields all undefined reference to the entire coapServer class.

c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o:(.text._Z14callback_lightP10coapPacket9IPAddressii+0x20): undefined reference to `coapServer::sendResponse(char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o:(.text._Z14callback_lightP10coapPacket9IPAddressii+0x24): undefined reference to `coapServer::sendResponse(IPAddress, int, char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o: in function `callback_light(coapPacket*, IPAddress, int, int)':
CoapServerEsp8266.cpp:(.text._Z14callback_lightP10coapPacket9IPAddressii+0xcb): undefined reference to `coapServer::sendResponse(char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text._Z14callback_lightP10coapPacket9IPAddressii+0xe7): undefined reference to `coapServer::sendResponse(IPAddress, int, char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o: in function `callback_rpm(coapPacket*, IPAddress, int, int)':
CoapServerEsp8266.cpp:(.text._Z12callback_rpmP10coapPacket9IPAddressii+0xbe): undefined reference to `coapServer::sendResponse(char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text._Z12callback_rpmP10coapPacket9IPAddressii+0xd9): undefined reference to `coapServer::sendResponse(IPAddress, int, char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o: in function `callback_temp(coapPacket*, IPAddress, int, int)':
CoapServerEsp8266.cpp:(.text._Z13callback_tempP10coapPacket9IPAddressii+0xbe): undefined reference to `coapServer::sendResponse(char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text._Z13callback_tempP10coapPacket9IPAddressii+0xd9): undefined reference to `coapServer::sendResponse(IPAddress, int, char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o: in function `callback_speed(coapPacket*, IPAddress, int, int)':
CoapServerEsp8266.cpp:(.text._Z14callback_speedP10coapPacket9IPAddressii+0xc2): undefined reference to `coapServer::sendResponse(char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text._Z14callback_speedP10coapPacket9IPAddressii+0xdd): undefined reference to `coapServer::sendResponse(IPAddress, int, char*)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o:(.text.setup+0x48): undefined reference to `coapServer::server(void (*)(coapPacket*, IPAddress, int, int), String)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o:(.text.setup+0x4c): undefined reference to `coapServer::start()'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o: in function `setup':
CoapServerEsp8266.cpp:(.text.setup+0x124): undefined reference to `coapServer::server(void (*)(coapPacket*, IPAddress, int, int), String)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text.setup+0x13e): undefined reference to `coapServer::server(void (*)(coapPacket*, IPAddress, int, int), String)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text.setup+0x158): undefined reference to `coapServer::server(void (*)(coapPacket*, IPAddress, int, int), String)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text.setup+0x172): undefined reference to `coapServer::server(void (*)(coapPacket*, IPAddress, int, int), String)'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: CoapServerEsp8266.cpp:(.text.setup+0x17f): undefined reference to `coapServer::start()'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o:(.text.loop+0x4): undefined reference to `coapServer::loop()'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o: in function `loop':
CoapServerEsp8266.cpp:(.text.loop+0x11): undefined reference to `coapServer::loop()'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o:(.text.startup._GLOBAL__sub_I_coap+0x0): undefined reference to `coapServer::coapServer()'
c:/users/maxi/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01\src\CoapServerEsp8266.cpp.o:(.text.startup._GLOBAL__sub_I_coap+0xf): undefined reference to `coapServer::coapServer()'
collect2.exe: error: ld returned 1 exit status

When I placed the coap_server.cpp and coap_server.h files in the project’s src/ directory and recompiled, it compiled.

DATA:    [===       ]  34.2% (used 28024 bytes from 81920 bytes)
PROGRAM: [======    ]  63.3% (used 274732 bytes from 434160 bytes)
 [SUCCESS] Took 11.03 seconds

So just put the needed coap_server.* files in the src directory oO?

That is great, I was putting these files under the include folder.

Thanks so much!
Regards
Paulo

Hi Max,

Now that I can compile the code above (thanks) I started the main task:
The debugging.

I have a JTAG device I acquired recently:
https://www.aliexpress.com/item/33044313716.html?spm=a2g0s.9042311.0.0.73a14c4ddfTp0t

It works fine in the Blink test I made with a ESP32.

But when I compile the ESP8266 (the one with the code above) it reports that:

Serial port COM8
Connecting……_____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2

How will it be possible to transfer the program and debug it using the JTAG and ESP8266?

[env:esp12e]
platform = espressif8266
board = esp12e
upload_protocol = esptool

Thanks again
Paulo

Flashing the firmware yes, debugging apparently no. See ESP-Prog — PlatformIO latest documentation

ESP-Prog’s automatic firmware downloading and serial communication functions are supported on both the ESP8266 and ESP32 platforms, while the JTAG online debugging is supported only on the ESP32 platform.

Why JTAG debugging is not supported for the ESP8266 is beyond my understanding though… When used with an ESP8266, this is basically a fancy USB-UART adapter for uploading the firmware, as many boards already have.

Also, PIO in general does not support debugging for the ESP8266, as can be seen when clicking on any of the boards and inspecting ‘Debgging’.

Hi Max, thanks again for your valuable assistance.

I checked the links you suggested, that is not the best news as I intended to debug this Coap server app precisely to understand some of its internal workings to eventually add some new functionality.

I will then have to find other ways.
Thanks again.
Regards
Paulo