philbowles / ESPAsyncWebServer

Patched version of the original
5 stars 1 forks source link

undefined reference to `AsyncWebServerRequest::beginResponse_P #1

Open DaeMonSx opened 3 years ago

DaeMonSx commented 3 years ago

Having seen your lib, I will try to replace the me-no-dev asynctcp and webserver with your libs. Getting this error, any hints to solve the issue? thanks

/Users/daemons/.platformio/packages/toolchain-xtensa@2.40802.200502/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /Users/daemons/0_iqHome_firmware/ESP8266/libaa1/libFixed ESP Async WebServer.a(WebRequest.cpp.o):(.text._ZN21AsyncWebServerRequest15beginResponse_PEiRK6StringPKcSt8functionIFS0_S2_EE+0x0): undefined reference to `AsyncWebServerRequest::beginResponse_P(int, String const&, unsigned char const*, unsigned int, std::function<String (String const&)>)'
/Users/daemons/.platformio/packages/toolchain-xtensa@2.40802.200502/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /Users/daemons/0_iqHome_firmware/ESP8266/libaa1/libFixed ESP Async WebServer.a(WebRequest.cpp.o): in function `AsyncWebServerRequest::beginResponse_P(int, String const&, char const*, std::function<String (String const&)>)':
WebRequest.cpp:(.text._ZN21AsyncWebServerRequest15beginResponse_PEiRK6StringPKcSt8functionIFS0_S2_EE+0x39): undefined reference to `AsyncWebServerRequest::beginResponse_P(int, String const&, unsigned char const*, unsigned int, std::function<String (String const&)>)'
serpinio commented 2 years ago

It's probably late to reply and I can understand why the original developer wouldn't bother with this issue, but for anyone who tries to use this forked lib as a drop-in replacement, make sure to not miss this important line from the author on "What's missing": All references to PROGMEM: an outdated hangover from Arduino code: totally unnecessary when proper memory management techniques are used.

beginResponse_P() and send_P() are not implemented here. Instead of these functions, call normal ones like beginResponse() or send(). They can handle PGM_P vars since those are basically const char type:

#define PGM_P const char *

Just make sure your PROGMEM variable is declared as a const char array. Example:

const char myHTMLPage[] PROGMEM = R"=====(
<!doctype html>page contents...
)=====";

Note that it should be a formatted string literal and not a byte array (basically should contain normal characters). The forked library doesn't really support streaming PROGMEM variable contents from flash, so the PROGMEM contents will be read from flash into RAM and implicitly converted to const String & (and sent as a reference). Once again: beware that the contents are first copied into RAM into a String object on the heap and then sent to the client! Make sure your page is not too large.

Then you can send the contents with a simple:

request->send(200, "text/html", myHTMLPage);

If you want to serve large pages that might not fit into RAM, you're better off actually reading a file from the filesystem and not from a variable:

request->send(LittleFS, "/myHTMLPage.html", "text/html");

HamzaHajeir commented 1 year ago

Hi there

Phil has passed away ~ 1year ago, you can checkout the stable H4AsyncWebServer, use my fork, a complete PlatformIO environment for H4Plugins is available.

You might check dependencies under platformio.ini.

serpinio commented 1 year ago

Oh my. Sorry to hear that.

Thank you for continuing his work!

HamzaHajeir commented 1 year ago

You're welcome..

On Sun, Jul 9, 2023, 13:15 serpinio @.***> wrote:

Oh my. Sorry to hear that.

Thank you for continuing his work!

— Reply to this email directly, view it on GitHub https://github.com/philbowles/ESPAsyncWebServer/issues/1#issuecomment-1627669535, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH3O7J6V3CU6AW7THF3ZYMTXPKADVANCNFSM4624QOPQ . You are receiving this because you commented.Message ID: @.***>