espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.63k stars 7.28k forks source link

Function gettimeofday isn't recognized (IDFGH-9002) #10413

Closed findmyname666 closed 1 year ago

findmyname666 commented 1 year ago

Answers checklist.

IDF version.

v5.1-dev

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

What is the expected behavior?

Based on the doc it should return the current time.

What is the actual behavior?

Compilation fails:

/home/findmyname/Documents/esp/project/test/main/main.c:519:5: error: implicit declaration of function 'gettimeofday'; did you mean '_gettimeofday_r'? [-Werror=implicit-function-declaration]
  519 |     gettimeofday(&tv_now, NULL);
      |     ^~~~~~~~~~~~
      |     _gettimeofday_r

Steps to reproduce.

I have this function:

static int64_t get_time(void)
{
    struct timeval tv_now;
    gettimeofday(&tv_now, NULL);
    return (int64_t)tv_now.tv_sec;
}

Build or installation Logs.

I executed these commands:

$ git checkout v5.1-dev
$ └──╼$ git submodule update --init --recursive
Submodule path 'components/bt/controller/lib_esp32': checked out 'c98341759b2c152c58878db6daf22d153a75fda4'
Submodule path 'components/bt/controller/lib_esp32c2/esp32c2-bt-lib': checked out 'bdab852aa2adf459d643731b513a4431003943b6'
Submodule path 'components/bt/controller/lib_esp32c3_family': checked out 'd1c2082e5633a89c6fd6051c7761c1e697cb7a2e'
Submodule path 'components/bt/host/nimble/nimble': checked out 'c1cb851c8562d0f1a4d105614c336341e2a535b2'
Submodule path 'components/esp_phy/lib': checked out '8d3ce02436066e33e8964d34981a97fe64edae2e'
Submodule path 'components/esp_wifi/lib': checked out '3a69afcd419114281a027d8792e2bfa03044fedd'
Submodule path 'components/ieee802154/lib': checked out 'd9838acadd72e5021cee5f79a897e195076d3645'
Submodule path 'components/lwip/lwip': checked out '3f5a04bc63c8c1b1509bfe06cf941a51c9e80d4a'
Submodule path 'components/mbedtls/mbedtls': checked out '9bb5effc3298265f829878825d9bd38478e67514'
Submodule path 'components/openthread/lib': checked out 'af1ac2b3770335db96702bcb06ca793a1425dc86'
Submodule path 'components/openthread/openthread': checked out 'c055c10a9a1362a96687614d4478dd2773e6ddc0'
Submodule path 'components/protobuf-c/protobuf-c': checked out 'f224ab2eeb648a818eb20687d7150a285442c907'

$ install.sh esp32 esp32s2



### More Information.

I had the same error on the latest master.
AxelLin commented 1 year ago

include <sys/time.h>

0xjakob commented 1 year ago

@findmyname666 does your code have the right includes, as @AxelLin suggested already?

findmyname666 commented 1 year ago

Yes it works with include. I'm playing with the older code and I think that it worked without include on older version of esp-idf.

0xjakob commented 1 year ago

@findmyname666

I think that it worked without include on older version of esp-idf.

That is possible if the IDF version is a different major version (e.g. 4.1 vs. 4.4). This is why we introduced migration guides.

If the problem appears when switching between minor versions (e.g. 4.4.1 vs. 4.4.2), then this shouldn't happen and is probably a bug.