使用Visual Studio 2015在C中执行Pthread程序时,出现以下错误:
Error C2011 'timespec': 'struct' type redefinition
Run Code Online (Sandbox Code Playgroud)
以下是我的代码:
#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);
}
Run Code Online (Sandbox Code Playgroud)
该pthread.h头文件包含有关的timespec下面的代码:
#if !defined(HAVE_STRUCT_TIMESPEC)
#define HAVE_STRUCT_TIMESPEC
#if !defined(_TIMESPEC_DEFINED)
#define _TIMESPEC_DEFINED
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#endif /* _TIMESPEC_DEFINED */
#endif /* HAVE_STRUCT_TIMESPEC */
Run Code Online (Sandbox Code Playgroud)
我使用的其他头文件timespec都没有使用struct,因此没有机会重新定义.由于已从pthread opensource网站下载,因此不存在损坏的头文件的可能性.