我刚刚升级到Fedora 20交叉编译项目。Fedora 20使用的是MinGW 4.8.2-1.fc 20。我的代码大多在那里,但在链接时,我得到了许多未定义的pthread_mutex_init和其他线程互斥函数的引用。我使用-mthreads选项链接,因为我的代码是多线程的,并且使用异常。
如果我说-pthread,链接错误就会消失。BUt,这似乎是不正确的想法去做。
下面是一个小测试程序:
#include <pthread.h>
int main(int argc,char **argv)
{
pthread_mutex_t M;
pthread_mutex_init(&M,0);
exit(0);
}样本汇编:
$ 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
$我可以让它消失:
$ x86_64-w64-mingw32-g++ -mthreads x.cpp -pthread
$但这似乎是错误的。
对于那些不熟悉-mthread的人,下面是手册页中的一节:
-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.有什么建议吗?
发布于 2014-04-22 13:58:05
您使用的是线程,所以使用-pthreads。-mthreads是另外一回事。
https://stackoverflow.com/questions/23220714
复制相似问题