error C2011: “timespec”:“struct”类型重定义

error C2011: “timespec”:“struct”类型重定义

C++ pthread pthread.h 中的 timespec 和time.h 中的 结构定义重复了 ,同时两个头文件中的条件编译条件不同,所以造成结构重复定义,简单快速见效的解决方法就是注释pthread.h 头文件中的struct timespce 定义

 warning C4477: “printf”: 格式字符串“%d”需要类型“int”的参数,但可变参数 1 拥有了类型“pthread_t”

print 中 传入pthread_t类型时报类型不匹配;

#include <stdio.h>
#include <iostream>
#include <Windows.h>
//#define HAVE_STRUCT_TIMESPEC 1;
#include <pthread.h>
//#include <>

//using namespace std;

#pragma comment(lib,"pthreadVC2.lib")




void *Function_T(void* Parm)
{
    pthread_t myid = pthread_self();
    while (1)
    {
        printf("线程ID=%lld 
", myid);
        //cout << "he" << endl;
        Sleep(6000);
    }
    return NULL;
}


int main(int argc, const char *argv[])
{
    pthread_t pid;
    pthread_create(&pid, NULL, Function_T, NULL);

    while (1)
    {
        printf("in fatherprocess!
");
        Sleep(2000);
    }
    getchar();
    return 1;
}

原文地址:https://www.cnblogs.com/ruiy/p/9705613.html