在使用Visual 2015在C中执行P线程程序时,我得到了以下错误:
Error C2011 'timespec':'struct‘类型重定义
以下是我的代码:
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
void *calculator(void *parameter);
int main(/*int *argc,char *argv[]*/)
{
pthread_t thread_obj;
pthread_attr_t thread_attr;
char *First_string = "abc"/*argv[1]*/;
pthread_attr_init(&thread_attr);
pthread_create(&thread_obj,&thread_attr,calculator,First_string);
}
void *calculator(void *parameter)
{
int x=atoi((char*)parameter);
printf("x=%d", x);
}发布于 2015-11-16 10:56:07
添加此编译器标志:
-DHAVE_STRUCT_TIMESPEC发布于 2018-04-07 08:15:26
尽管这个问题已经得到了正确的回答,但也有另一种解决办法。
首先,出现问题是因为pthreads-win32内部包含已声明timespec struct的time.h。
为了避免这一错误,我们应该做的唯一一件事是:
#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>发布于 2016-06-03 08:36:41
在Visual 2015中编译包含MariaDB 10头文件的程序时也会出现同样的问题(见10.1.14)。
这里的解决方案是定义以下内容:
STRUCT_TIMESPEC_HAS_TV_SEC
STRUCT_TIMESPEC_HAS_TV_NSEChttps://stackoverflow.com/questions/33114535
复制相似问题