一、下載Windows版本的pthread
????目前最新版本是:pthreads-w32-2-9-1-release.zip。
?
二、解壓pthread到指定目錄
我選擇的目錄是:E:\DEV-CPP\Pthread
完成后,該目錄會多出三個文件夾:Pre-built.2,pthreads.2,QueueUserAPCEx。
三、配置Dev-C++編譯選項
????1)點擊“工具”→“編譯選項”→“目錄”→“c++包含文件”,瀏覽到剛才解壓的pthread目錄,選擇E:\DEV-CPP\Pthread\Pre-built.2\include,添加。?
????2)點擊“工具”→“編譯選項”→“目錄”→“庫”,瀏覽到剛才解壓的pthread目錄,選擇E:\DEV-CPP\Pthread\Pre-built.2\lib,添加。
?
四、如果出現“undefined reference to 'pthread_create”的錯誤,在編譯器選項中要加 -lpthread參數五、最后附上一個簡單的多線程的例子#include <iostream> #include <pthread.h> #include<cstdio> using namespace std; void* hjzgg(void* arg) { while(1){cout<<"Hello, everyone! I am hjzgg!"<<endl; getchar();}return NULL; } int main(int args, char* argv[]) { pthread_t tid; pthread_create(&tid, NULL, hjzgg, NULL); while(1);//主線程不要提前結束 return 0; }?