带有“timespec"结构的 Visual Studio 错误 [英] Visual Studio error with 'timespec' structure

查看:82
本文介绍了带有“timespec"结构的 Visual Studio 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Visual Studio 2015 在 C 中执行 Pthread 程序时,出现以下错误:

While executing a Pthread program in C using Visual Studio 2015, I got the following 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);
}

推荐答案

添加这个编译器标志:

-DHAVE_STRUCT_TIMESPEC

这篇关于带有“timespec"结构的 Visual Studio 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆