cygwin可以使用gettimeofday()吗?我得到了一个错误:
lab8.cpp: In function ‘int main()’:
lab8.cpp:62:30: error: ‘gettimeofday’ was not declared in this scope
gettimeofday(&start, NULL);
^
makefile:14: recipe for target 'lab8.o' failed
make: *** [lab8.o] Error 1我绝对把<sys/time.h>也包括进来了。有没有我必须安装的包,或者它在Windows上不起作用?
编辑:下面是一个简单的测试,它会产生相同的错误:
#include <sys/time.h>
int main() {
struct timeval start;
gettimeofday(&start, NULL);
}出现以下错误:
$ g++ -c -Wall -g -std=c++11 test.cpp -o test.o
test.cpp: In function ‘int main()’:
test.cpp:6:30: error: ‘gettimeofday’ was not declared in this scope
gettimeofday(&start, NULL);发布于 2016-04-28 06:43:14
你需要定义_BSD_SOURCE来包含gettimeofday声明(根据下面的链接,从glibc2.2.2开始)
#define _BSD_SOURCE
#include <sys/time.h>
int main() {
struct timeval start;
gettimeofday(&start, NULL);
}gettimeofday() - Unix, Linux System Call
发布于 2017-10-11 18:18:09
谢谢你,约翰-你的问题游戏我的答案!
以防对其他搜索此错误的人有所帮助...我得到了同样的错误:
error: ‘gettimeofday’ was not declared in this scope
gettimeofday(&lastBigTick, NULL);这个错误是在我在树莓派上从Debian 8 (jessie)转移到Debian 9 (stretch)时开始发生的
对我来说,我没有#included "sys/time.h“我只有#included "time.h”不确定它以前是如何编译的,但它确实编译了,所以添加了
#include "sys/time.h"为我做了这件事。
注意:"time.h“是不同的,其他时间函数仍然需要它,所以我最终两者都需要:
#include "time.h"
#include "sys/time.h"我的情况可能有所不同,因为我补充说
#define _BSD_SOURCE对我来说没什么不同(这不是我的问题)。
https://stackoverflow.com/questions/36901803
复制相似问题