Returning String doesn't work?

Hi there

I fetched some code from an example elsewhere, but there’s one function I cannot get to work:

String getResponse() {
    char rx_buffer[2048];
    int bufflen=2048;
    int recLen = 0;
    
    memset(rx_buffer, 0, sizeof(rx_buffer));
    
    
    // wait until data is available, max 5 seconds
    uint32_t sT = millis();
    while(!client.available() && (millis() - sT) < 5000) {
        //delay(1);
    }
    
    recLen = client.available();
    
    if (recLen > 0)
    {
        // read from client to the buffer, for length of bytes
        for (int i = 0;  i  < recLen && i < bufflen; i++) {
            char rec = client.read();
            if (rec == -1) {
                break;
            }
            rx_buffer[i] = rec;
        }
    } else {
        return NULL;
    }
    
    
    // make string from buffer
    String rx_string(rx_buffer);
    
    #ifdef RESPONSEDEBUG
        Serial.print("[INF] response length: ");
        Serial.println(rx_string.length());
    #endif

    return rx_string;
    
}

I get the error when trying to parse it in the editor:

first_project.o: In function getResponse()': /spark/compile_server/shared/workspace/2_compile-server2/core-firmware/build/first_project.cpp:436: undefined reference toString::String(String&&)'
collect2: error: ld returned 1 exit status
make: *** [bd9a6ffc0b3a229597e71812b072c69237f53f3caeedee0d418b177968cd.elf] Error 1

The sample project I’m partly using is: https://github.com/phhe/sparkSo/blob/master/application.cpp

Any ideas?

BR
Michael

@Vognsen, you may want to refer to this topic:

:smile: