linux 'pthread_create'未定义的引用,如何解决`_imp__pthread_create'的未定义引用

的命令行:

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值