PlatformIO Community

'time' not declared in Platformio but works in Arduino IDE

I am trying to compile this sketch with Platformio in VSCode:
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
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! :slight_smile:

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):

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.


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?

  1. It doesn’t have the automatic library dependency finder that PlatformIO has
  2. But actually it should be if you install the Time library in Arduino IDE and reference time.h… have you tried that for fun?

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