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; }

