首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >-mthreads on mingw 4.8.2 (在Fedora 20上)现在会产生lihnking错误-我应该同时使用-mthreads和-pthread吗?

-mthreads on mingw 4.8.2 (在Fedora 20上)现在会产生lihnking错误-我应该同时使用-mthreads和-pthread吗?
EN

Stack Overflow用户
提问于 2014-04-22 13:13:57
回答 1查看 434关注 0票数 0

我刚刚升级到Fedora 20交叉编译项目。Fedora 20使用的是MinGW 4.8.2-1.fc 20。我的代码大多在那里,但在链接时,我得到了许多未定义的pthread_mutex_init和其他线程互斥函数的引用。我使用-mthreads选项链接,因为我的代码是多线程的,并且使用异常。

如果我说-pthread,链接错误就会消失。BUt,这似乎是不正确的想法去做。

下面是一个小测试程序:

代码语言:javascript
复制
#include <pthread.h>

int main(int argc,char **argv)
{
    pthread_mutex_t M;
    pthread_mutex_init(&M,0);
    exit(0);
}

样本汇编:

代码语言:javascript
复制
$ x86_64-w64-mingw32-g++ -mthreads x.cpp
/tmp/ccqTnLlg.o:x.cpp:(.text+0x21): undefined reference to `pthread_mutex_init'
collect2: error: ld returned 1 exit status
$

我可以让它消失:

代码语言:javascript
复制
$ x86_64-w64-mingw32-g++ -mthreads x.cpp -pthread
$

但这似乎是错误的。

对于那些不熟悉-mthread的人,下面是手册页中的一节:

代码语言:javascript
复制
   -mthreads
       Support thread-safe exception handling on MinGW.  Programs that rely on thread-safe exception handling must compile and link all code with the
       -mthreads option.  When compiling, -mthreads defines "-D_MT"; when linking, it links in a special thread helper library -lmingwthrd which
       cleans up per-thread exception-handling data.

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-22 13:58:05

您使用的是线程,所以使用-pthreads-mthreads是另外一回事。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23220714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档