虽然使用Visual Studio 2015年用C执行的Pthread程序,我得到了以下错误:TIMESPEC重新定义错误
Error C2011 'timespec': 'struct' type redefinition
以下是我的代码:
#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);
}
的pthread.h
头文件包含以下与timepec相关的代码:
#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 */
No other header f我使用的是使用timespec
结构,所以没有重新定义的机会。没有机会损坏头文件,因为它已从pthread开源网站下载。
该错误发生在哪条线上? – user3386109
@ user3386109没有提到的行号,当我点击错误时,它正在pthreads中加载以下内容:cpp struct timespec {0} {0} {0} {0} time_t tv_sec; long tv_nsec; }; –
错误总是有文件名和行号。但无论如何,我会说项目文件已损坏,或系统头文件已损坏。这两者都不能通过互联网进行诊断。 – user3386109