I want to use WiFiServer and in the main file and in a second cpp file.
When I declare it in the main and and in the main.h file with the extern directive I get error:
redefinition of ‘WiFiServer server’
Hi.
I think this discussion might help:
Regards,
Sara
This is how to do split a program into muliple files. Ok, I know.
But my question is specific about WiFiServer.
How and where to declare/define this so it is reachable within main.cpp and a module.cpp.
When I declare it in main.cpp and in main.h( with the extern directive) I get an error
“redefinition of ‘WiFiServer server’”. The h-file contains a wrapper of course.
Hi.
I’m not sure how to solve that issue.
Were you able to solve it yet?
I think it is better to ask for help on the PlatformIO forum for ESP32: https://community.platformio.org/
I’m sorry that I can’t help much.
Regards,
Sara
You may like to try compiler directives in both files:
#ifndef server
WiFiServer server
#endif
A useful tutorial on compiler directives can be found at https://www.deviceplus.com/arduino/arduino-preprocessor-directives-tutorial/
My error:
In main.cpp I declared “WiFiServer(80)”
and in main.h “extern WiFiServer(80)”.
The last I had to change into “extern WiFiServer server;”
Now it is correct.
Thanks.