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 \n", 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!\n");
        Sleep(2000);
    }
    getchar();
    return 1;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM