Hello,
I am trying to compile this sketch with Platformio in VSCode: https://github.com/scanlime/esp8266-Arduino/blob/master/tests/Time/Time.ino
It works without a problem in the Arduino IDE but in Platformio I get the following error message:
src\main.cpp: In function 'void setup()':
src\main.cpp:27:23: error: 'time' was not declared in this scope
while (!time(nullptr))
^
src\main.cpp: In function 'void loop()':
src\main.cpp:37:28: error: 'time' was not declared in this scope
time_t now = time(nullptr);
^
src\main.cpp:38:28: error: 'ctime' was not declared in this scope
Serial.println(ctime(&now));
Archiving .pio\build\d1_mini\libfd7\libTime_ID44.a
^
*** [.pio\build\d1_mini\src\main.cpp.o] Error 1
It seems to refer to the time.h in ‘.platformio\packages\framework-arduinoespressif8266\tools\sdk\lwip\include\lwip\app’. If I add this path to my include path like this
include_dir = C:/Users/klaraWasser/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lwip/include/lwip/app
it won’t work either. However in the Arduino IDE it works without a problem. I have encountered such problems a lot with Platformio. I have been using Deviot with Sublime Text before and it also caused way less problems than Plaformio with VSCode.
Hopefully someone can help me with this one! 
Which Arduino IDE version and which ESP8266 board package version are we talking about?
I am using the latest Arduino IDE 1.8.9 with esp8266 board version 2.5.2.
In Platformio I’m using the latest Espressif 8266 platform version 2.2.2.
By the way my platformio.ini looks like this (default):
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
It attempts to include a Time
library (ID 44) because it reads the #include <time.h>
header. This library then has a Time.h
and because Windows has a case-insensitive filesystem, time.h = Time.h
, causing the main code to not find the actual C standard lib time functions.
You can add to your platformio.ini
lib_ignore = Time
and clear the .pio
(invisible folder) just to be sure you don’t have the Time
library anymore.
However actually it would be nice if firmware developers, who write C++ code, do #include<ctime>
. Then there would no possibility of confusion.
3 Likes
Wow, that’s it. And I thought the answer would be much easier. That’s actually not something a newbie would be able to find that easily. Thanks!
But why does the Arduino IDE not get confused here?
Not should… does! I have gone down that road more than once with the Arduino IDE and Time library, and had to rename and edit the files…
I’m not familiar with ctime… where would that get included?
1 Like
That is really interesting and I’m glad I asked this question here. Really insightful. Thanks guys!
1 Like