微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

对“_gettimeofday”的未定义引用

如何解决对“_gettimeofday”的未定义引用

我正在用 C 语言为 Zolertia 模块做一个项目,但是在尝试编译它时出现错误。 '_gettimeofday_r'函数好像有点问题。

这是我的代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h> 
#include "contiki.h"
#include <time.h>
#include <sys/time.h>

/*---------------------------------------------------------------------------*/
PROCESS(temp_hum_fog,"Controle de Incendio");
AUTOSTART_PROCESSES(&temp_hum_fog);
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(temp_hum_fog,ev,data)
{
    PROCESS_BEGIN();

    int16_t temp,hum,id,subid,graph,integer,fraction,fumo,c;
    time_t current_time;
    struct tm *info;
    int hour;

    while(1){

        etimer_set(&et,CLOCK_SECOND);
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
        id=0;subid=0;graph=0;
        int i;
        for (i=1;i<19;i++){
            id=id+1;
            switch(id){
                case 1:
                    c=19;
                    break;
                case 2:
                    c=14;
                    break;
                case 3:
                    c=14;
                    break;
                case 4:
                    c=12;
                    break;
                case 5:
                    c=11;
                    break;
                case 6:
                    c=17;
                    break;
                case 7:
                    c=14;
                    break;
                case 8:
                    c=16;
                    break;
                case 9:
                    c=14;
                    break;
                case 10:
                    c=16;
                    break;
                case 11:
                    c=16;
                    break;
                case 12:
                    c=15;
                    break;
                case 13:
                    c=18;
                    break;
                case 14:
                    c=21;
                    break;
                case 15:
                    c=13;
                    break;
                case 16:
                    c=10;
                    break;
                case 17:
                    c=14;
                    break;
                case 18:
                    c=24;
                    break;
            }
            int z;
            for(z=1;z<=c;z++){
                subid=subid+1;

                time(&current_time);
                info=localtime(&current_time);

                hour=(info->tm_hour)-1;
                //printf("%d\n",hour);
                int ho;
                for (ho=0;ho<=hour;ho++){
                    temp = rand() % 45;
                    hum = rand() % (85-5)+5;
                    fumo = rand() % 1;
                    integer = temp/hum;
                    fraction = temp%hum * 100 / hum;
                    graph = graph +1;

                    printf("ID: %d\n Sub ID: %d\nTemperatura:%d ºC\nHumidade:%d HR\nIndice de Risco de Deflagaçao de Incendio:%d.%02d\n Fumo: %d\nHora: %d\n",temp,graph);
                }
                graph = 0;
            }
        }
        
    }

这是尝试编译时发生的错误

user@iot-workshop:~/Desktop/Projeto$ make
using saved target 'zoul'
  CC        ../../contiki//cpu/cc2538/./ieee-addr.c
  CC        ../../contiki//cpu/cc2538/cc2538.lds
  CC        ../../contiki//cpu/cc2538/./startup-gcc.c
  CC        ines_projecto.c
  LD        ines_projecto.elf
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7-m/libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/armv7-m/newlib/libc/reent/../../../../../../newlib/libc/reent/gettimeofdayr.c:71: undefined reference to `_gettimeofday'
collect2: error: ld returned 1 exit status
../../contiki//cpu/cc2538/Makefile.cc2538:100: recipe for target 'ines_projecto.elf' Failed
make: *** [ines_projecto.elf] Error 1
rm obj_zoul/startup-gcc.o ines_projecto.co

我还将包括我的 Makefile:

DEFInes+=PROJECT_CONF_H=\"project-conf.h\"

CONTIKI_PROJECT = ines_projecto

all: $(CONTIKI_PROJECT)

CONTIKI = ../../contiki/
include $(CONTIKI)/Makefile.include

我已经尝试寻找解决方案,但找不到任何解决方案。我想可能是我忘记添加一些库了,但我不认为是这样。

有人知道为什么会这样吗?

非常感谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。