Compiler error-Possible IDE error“undefined reference to gettimeofday error”

只谈情不闲聊 提交于 2019-12-10 20:33:10

问题


I am trying to use rand,srand and time to generate random(enough) numbers in C.I use DEVC++.I get the following error: [Linked Error]undefined reference to 'gettimeofday' error

Here is my code:

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

static unsigned long next = 1;

    int myrand(void) {
next = next * 1103515245 + 12345;
return((unsigned)(next/65536) % 32768);
}

void mysrand(unsigned seed) {
next = seed;
}

struct  {
   long tv_sec;
   long tv_usec;
       }timeval ;

int main(){


int num=0;               //random number

struct timeval t1;  


gettimeofday(&t1, NULL);
srand(t1.tv_usec * t1.tv_sec);

arg_num=rand();

printf("Number of arguments is:%d\n",arg_num);

}

Making an online research i found out that DEVC++ (somehow) includes GNU compiler but it doesn't really use it and that results in not identifying all "common" functions. Beyond solving the linked error, i would like to know if there is an IDE for C programming in Windows that uses GNU or that will not making such problems..


回答1:


There is no gettimeofday() provided by Windows.



来源:https://stackoverflow.com/questions/13894732/compiler-error-possible-ide-errorundefined-reference-to-gettimeofday-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!