khoih-prog / Portenta_H7_AsyncWebServer

Asynchronous WebServer Library for STM32H7-based Portenta_H7 using mbed_portenta core. This library, which is relied on Portenta_H7_AsyncTCP, is part of a series of advanced Async libraries, such as AsyncTCP, AsyncUDP, AsyncWebSockets, AsyncHTTPRequest, AsyncHTTPSRequest, etc. Now supporting using CString in optional SDRAM to save heap to send very large data
GNU Lesser General Public License v3.0
12 stars 3 forks source link

Compiling Library into application #4

Closed salasidis closed 2 years ago

salasidis commented 2 years ago

I posted this in the arduino forum, but not sure if it should go here as well

If I compile the example, it works OK

However, if I try to use the async library in my application, the moment I issue a

include

I get the following errors

WARNING: library MRI claims to run on mbed architecture(s) and may be incompatible with your current board which runs on mbed_portenta architecture(s).
In file included from \\SERVER846C\DS_846a\Projects\EnviroWatch\Code\MainCode\EnviroWatch\EthernetInterface.ino:15:0:
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:343:15: error: reference to 'Stream' is ambiguous
     void send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
               ^~~~~~
In file included from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/ArduinoAPI.h:36:0,
                 from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/Arduino.h:27,
                 from sketch\EnviroWatch.ino.cpp:1:
C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/Stream.h:50:7: note: candidates are: class arduino::Stream
 class Stream : public Print
       ^~~~~~
In file included from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/mbed/mbed.h:109:0,
                 from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/mbed.h:8,
                 from \\SERVER846C\DS_846a\Projects\EnviroWatch\Code\MainCode\EnviroWatch\EnviroWatch.ino:16:
C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/mbed/platform/include/platform/Stream.h:42:7: note:                 class mbed::Stream
 class Stream : public FileLike, private NonCopyable<Stream> {
       ^~~~~~
In file included from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/ArduinoAPI.h:36:0,
                 from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/Arduino.h:27,
                 from sketch\EnviroWatch.ino.cpp:1:
C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/Stream.h:50:7: note:                 class arduino::Stream
 class Stream : public Print
       ^~~~~~
In file included from \\SERVER846C\DS_846a\Projects\EnviroWatch\Code\MainCode\EnviroWatch\EthernetInterface.ino:15:0:
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:343:15: error: 'Stream' has not been declared
     void send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
               ^~~~~~
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:349:29: error: expected ';' at end of member declaration
     AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
                             ^~~~~~~~~~~~~
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:349:43: error: 'AsyncWebServerResponse* AsyncWebServerRequest::beginResponse' conflicts with a previous declaration
     AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
                                           ^~~~~~
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:347:29: note: previous declaration 'AsyncWebServerResponse* AsyncWebServerRequest::beginResponse(int, const arduino::String&, const arduino::String&)'
     AsyncWebServerResponse *beginResponse(int code, const String& contentType = String(), const String& content = String());
                             ^~~~~~~~~~~~~
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:349:50: error: expected ')' before '&' token
     AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
                                                  ^
In file included from C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:634:0,
                 from \\SERVER846C\DS_846a\Projects\EnviroWatch\Code\MainCode\EnviroWatch\EthernetInterface.ino:15:
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebResponseImpl.h:94:5: error: reference to 'Stream' is ambiguous
     Stream *_content;
     ^~~~~~
In file included from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/ArduinoAPI.h:36:0,
                 from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/Arduino.h:27,
                 from sketch\EnviroWatch.ino.cpp:1:
C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/Stream.h:50:7: note: candidates are: class arduino::Stream
 class Stream : public Print
       ^~~~~~
In file included from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/mbed/mbed.h:109:0,
                 from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/mbed.h:8,
                 from \\SERVER846C\DS_846a\Projects\EnviroWatch\Code\MainCode\EnviroWatch\EnviroWatch.ino:16:
C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/mbed/platform/include/platform/Stream.h:42:7: note:                 class mbed::Stream
 class Stream : public FileLike, private NonCopyable<Stream> {
       ^~~~~~
In file included from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/ArduinoAPI.h:36:0,
                 from C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/Arduino.h:27,
                 from sketch\EnviroWatch.ino.cpp:1:
C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\cores\arduino/api/Stream.h:50:7: note:                 class arduino::Stream
 class Stream : public Print
       ^~~~~~
In file included from C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebServer.h:634:0,
                 from \\SERVER846C\DS_846a\Projects\EnviroWatch\Code\MainCode\EnviroWatch\EthernetInterface.ino:15:
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebResponseImpl.h:97:32: error: expected ')' before '&' token
     AsyncStreamResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
                                ^
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebResponseImpl.h: In member function 'virtual bool AsyncStreamResponse::_sourceValid() const':
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebResponseImpl.h:101:17: error: '_content' was not declared in this scope
       return !!(_content);
                 ^~~~~~~~
C:\Users\Mydir\Documents\Arduino\libraries\Portenta_H7_AsyncWebServer-1.2.1\src/Portenta_H7_AsyncWebResponseImpl.h:101:17: note: suggested alternative: '_code'
       return !!(_content);
                 ^~~~~~~~
                 _code
Multiple libraries were found for "WiFiClient.h"
 Used: C:\Users\Mydir\AppData\Local\Arduino15\packages\arduino\hardware\mbed_portenta\3.0.1\libraries\WiFi
 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
 Not used: C:\Users\Mydir\Documents\Arduino\libraries\WiFiEspAT
exit status 1
Error compiling for board Arduino Portenta H7 (M7 core).

Mostly there seems to be am issue with the Stream class

I have tried adding

using namespace mbed;

or

using namespace arduino;

before the #include but that did not work.

Any ideas how to resolve this? I am using some mbed specific features, such as threads and the chrono library.

Thanks

khoih-prog commented 2 years ago

Hi @salasidis

If I compile the example, it works OK

If you can compile the library's examples without any issue, the problem is in your code.

To fix it, you have to identify which Stream class must use arduino:: prefix, and which one to use mbed:: prefix.

Try not blindly use

using namespace mbed;

or

using namespace arduino;

This is simple scope-relating problem to solve, and you must know and be sure which data type, from which part you'd like to use before putting into your code.

Certainly no one can help you here without your full code. Even with your full code, I'm afraid no one will be interested in helping you solving the issue not-related to this library.

Your post AsyncWebServer library on Arduino Forum is a good place to start for general programming issue.

Good Luck,

khoih-prog commented 2 years ago

For the record, the issue was solve by the OP, posted as AsyncWebServer library

I removed all reference to using namespace from my code, and added mbed::, rtos:: as required for the used function in my code, and then it compiled.

I also had to add definitions for

void handleRoot(AsyncWebServerRequest *request);
void handleNotFound(AsyncWebServerRequest *request);
void drawGraph(AsyncWebServerRequest *request);

to make sure the WebServer sample code compiled - should not have been necessary, as the function code was present before it was ever called, but the errors went away when I declared them as above in my header.