的命令行:
gcc -I /usr/local/include -L /usr/local/lib/libpthread.dll.a trylpthread.c
没有意义。
-L
您发布的程序都没有意义。该行:
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
说: -
如果我有不定义的宏pthread_create一个预处理然后编译:
return ((int*)(&pthread_create))[argc];
否则编译:
(void)argc;
return 0;
那么,如果你已经定义了一个预处理器宏pthread_create,例如
#define pthread_create whatever
,那么你会编译代码是:
(void)argc;
return 0;
而且因为你确实没有定义任何这样的宏,您编译的代码是:
return ((int*)(&pthread_create))[argc];
从而未能在链接,如你所见。如果该代码是这么定义的pthread_create编译, 这将是:
return ((int*)(&whatever))[argc];
重写你的程序为:
#include
#include
int main(int argc, char** argv)
{
(void)argv;
printf("######## start \n");
return ((int*)(&pthread_create))[argc];
}
编译:
gcc -Wall -I /usr/local/include -o trylpthread.o -c trylpthread.c
与链接:
gcc -o trylpthread.exe trylpthread.o /usr/local/lib/libpthread.dll.a
请记住,当你的程序编译和链接,适当pthreadGC??.dll 必须在运行在的DLL程序加载器搜索的地方之一找到。
更好的是,卸载您的MinGW并且您的pthreads-w32-2.8.0-3-mingw32-dev和 会安装更新的GCC Windows端口,例如, TDM-GCC(最简单)或mingw-w64。如果您的Windows系统 是32位,请选择32位版本。这些工具链内置了pthread支持,正如GCC标准所做的那样。
编译:
gcc -Wall -o trylpthread.o -c trylpthread.c
链接有:
gcc -o trylpthread.exe trylpthread.o -pthread
(不-lpthread)