Visual Studio 2015 を使用して C で Pthread プログラムを実行しているときに、次のエラーが発生しました。
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
ヘッダー ファイルには、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 */
私が使用する他のヘッダー ファイルは構造体を使用しtimespec
ないため、再定義する機会はありません。ヘッダー ファイルは pthread オープンソース Web サイトからダウンロードされているため、ヘッダー ファイルが破損する可能性はありません。