Example doesn't compile because Time.h
ssaguiar opened this issue · 5 comments
Your example doesn't compile:
I am using PlatformIO to compile:
Processing nodemcuv2 (platform: espressif8266, lib_deps: ESPAsyncTCP, board: n
odemcuv2, framework: arduino)
.
.
.
.
lib\ESPAsyncWebServer\src\WebHandlers.cpp: In member function 'AsyncStaticWebHandler& AsyncStaticW
ebHandler::setLastModified(tm*)':
lib\ESPAsyncWebServer\src\WebHandlers.cpp:67:64: error: 'strftime' was not declared in this scope
strftime (result,30,"%a, %d %b %Y %H:%M:%S %Z", last_modified);
^
lib\ESPAsyncWebServer\src\WebHandlers.cpp: In member function 'AsyncStaticWebHandler& AsyncStaticW
ebHandler::setLastModified(time_t)':
lib\ESPAsyncWebServer\src\WebHandlers.cpp:72:60: error: 'gmtime' was not declared in this scope
return setLastModified((struct tm *)gmtime(&last_modified));
^
lib\ESPAsyncWebServer\src\WebHandlers.cpp: In member function 'AsyncStaticWebHandler& AsyncStaticW
ebHandler::setLastModified()':
lib\ESPAsyncWebServer\src\WebHandlers.cpp:77:25: error: 'time' was not declared in this scope
if(time(&last_modified) == 0) //time is not yet set
^
*** [.pioenvs\nodemcuv2\lib\ESPAsyncWebServer\WebHandlers.o] Error 1
[ERROR] Took 97.28 seconds
Any ideas?
I had similar issues with some incompatible time libraries.
If you use the preferred Time library (https://github.com/PaulStoffregen/Time) you can use
#include Timelib.h
instead of Time.h
The time library uses an header file with an uppercase T, while there are some other time.h with an lower-case t from other projects.
OSses like Windows and Mac don't make an difference there :-(
I have this problem also, on windows only, not linux. I solved it by deleting the "Time.h" from the Time library (https://github.com/PaulStoffregen/Time), and using TimeLib.h only in my code.
This compilation problem happens in Windows only. Linux and Mac are case sensitive for files, so these OSes differ between time.h
and Time.h
. Windows doesn't.
The problem comes when Time_ID44
lib in installed (that's often used lib) and ESPAsyncWebServer_ID306
lib includes time.h
in WebHandlerImpl.h
.
So wrong time lib is included due to OS case insensitivity.
There is advice to include TimeLib.h
instead of time.h
. Tried this, doesn't work.
Workaround that works:
- Rename the lib:
- Go to: disk:\Users\username\.platformio\packages\toolchain-xtensa\xtensa-lx106-elf\include
- Rename
time.h
to_time.h
.
- Find all occurrences of
WebHandlerImpl.h
in your Windows. Replace#include <time.h>
with#include <_time.h>
- Build your project. (Recommended restart platformio before the build).
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.