问题描述
我试图使用rand,srand和时间生成随机(足够的)数字在CI使用DEVC ++。我得到以下错误:[链接错误]未定义的引用gettimeofday错误
这是我的代码:
#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(参数个数:%d \\\
,arg_num);
}
在线调查我发现DEVC ++包括GNU编译器,但它并没有真正使用它,导致不能识别所有的通用函数。
除了解决链接的错误,我想知道是否有一个IDE的C编程在Windows中使用GNU或不会产生这样的问题..
Windows没有gettimeofday()。
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..
There is no gettimeofday() provided by Windows.
这篇关于编译器错误 - 可能的IDE错误“未定义的gettimeofday错误引用”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!