windows下的pthread库,和linux下一模一样,爽。
windows下的pthread库叫做:pthreads-win32,官方网站是:http://sourceware.org/pthreads-win32/,官方FTP是:
ftp://sources.redhat.com/pub/pthreads-win32/。
郁闷的是,FTP里面的内容比较乱,部分已经编译的库有问题。我下载了一个看起来比较新的库,结果弄了半天不能链接。建议大家下载:
ftp://sources.redhat.com/pub/pthreads-win32/pthreads-w32-2-7-0-release.exe这个自解压文件,压缩包里的pthreads.2目录是源码,
Pre-built.2目录是编译所需的头文件和库文件。
先把pthreads-w32-2-7-0-release.exe解压缩到c:/pthreads-w32-2-7-0-release文件夹。
OK!现在写一个简单的pthread来测试:




























OK!使用微软的CL来编译:
rem cl.bat
cl.exe main.cpp /c /I"c:/pthreads-w32-2-7-0-release/Pre-built.2/include"
link.exe /out:main_cl.exe main.obj /LIBPATH:"c:/pthreads-w32-2-7-0-release/Pre-built.2/lib" pthreadVC2.lib
pause
或者使用GCC来编译:
rem gcc.bat
g++.exe -o main.o -c main.cpp -I"c:/pthreads-w32-2-7-0-release/Pre-built.2/include"
g++.exe -o main_gcc.exe main.o "c:/pthreads-w32-2-7-0-release/Pre-built.2/lib/libpthreadGC2.a"
pause