PlatformIO Community

Identifier is undefined - setenv tzset

Hi,

Is anybody familiar with below error on compiling code for esp32 based on arduino framework in platformio ?

identifier “setenv” is undefined
identifier “tzset” is undefined

I am working on an ubuntu machine. It appears setenv is part of stdlib.h and tzset is part of time.h. But i think the arduino framework libraries are not having these. These appear to be part of regular c/c++ libraries which am not sure if my program compilation is seeing them ?

  1. For arduino framework to support it, does some special libraries needs to be installed ? How ?
  2. Can i use the external gcc c/c++ library paths into this esp32 project ? How ?

Thanks,
Rajesh

Code like

#include <time.h>
#include <cstdlib>

void setup() {
    setenv( "TZ", "PST8PDT", 1 );
    tzset(); 
}

void loop() {}

does compile and is advertised to work by the underlying ESP-IDF layer.

There is just an Intellisense error, which comes from the fact that there are multiple time.h files in the include path of the compiler and that a macro is set which comments out the definition of those functions.

Same for setenv()

And __STRICT_ANSI__ is defined by the compiler in the Intellisense, but obviously the /tools/sdk/lib/libc_nano.a contains the definitions so it was compiled without the strict ANSI.

Not sure how to put the compiler during Intellisense into the mode so that __STRICT_ANSI__ is not defined and these extended functions are compiled in. If you just want to get rid of the Intellisense errors you can copy-paste the declaration on top of the sketch.

#include <Arduino.h>

_VOID      _EXFUN(tzset,	(_VOID));
int	_EXFUN(setenv,(const char *__string, const char *__value, int __overwrite));
1 Like

thanks a lot thats much cleaner.

i figured if i put #undef STRICT_ANSI , its working, but definitely your solution is better.

Thanks,
Rajesh