std ::线程在MacPorts gcc4.5 [英] std::thread in MacPorts gcc4.5

查看:135
本文介绍了std ::线程在MacPorts gcc4.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译一些我在Linux上编写的软件,它在我的Mac上使用了一些新奇的C ++ 0x功能。我使用MacPorts来安装gcc45软件包,它给了我/opt/local/bin/g++-mp-4.5,但是这个编译器不想编译< thread> 。例如,我尝试编译:

  // test.cpp 
#include< thread>

int main()
{
std :: thread x;
返回0;
}

并获得:

  bash-3.2 $ /opt/local/bin/g++-mp-4.5 -std = c ++ 0x test.cpp 
test.cpp:In function'int main ()':
test.cpp:5:2:error:'thread'不是'std'的成员
test.cpp:5:14:error:expected';'before'x '



快速查看/ opt / local / include / gcc45 / c ++ / ::线程类被定义,但由以下内容保护:

  #if defined(_GLIBCXX_HAS_GTHREADS)&&定义(_GLIBCXX_USE_C99_STDINT_TR1)

再一次,这在我的Ubuntu机器上完美运行,那么启用g ++ 4.5(g ++ - mp-4.5)的MacPorts版本下的c ++ 0x < thread> 库?如果没有,我需要知道什么(配置标志等),然后才开始编译gcc 4.5自己?



更新:
它看起来并不像SO社区对此有多少了解,所以现在是时候离开发商一点点了。有谁知道我可以将这个问题转发给官方邮件列表吗?是否有任何礼仪提示可以帮助我获得答案?



更新2:
我问过另一个临时解决方案这里,所以我现在只是用boost :: thread库替换std的人。不幸的是,没有boost :: future,所以这还不是一个完整的解决方案。任何帮助仍将不胜感激。

解决方案

实际上< thread> 库在Mac OS X下不起作用,因为这里的pthreads没有超时的函数(例如pthread_mutex_timedlock())。此功能的可用性必须使用<$ 检查 c $ c> _POSIX_TIMEOUTS 宏,但在Mac OS X 10.4,10.5和10.6中定义为 -1 (我不知道10.7是什么)并且这个函数在 pthread.h中不存在。


$ b $ < _POSIX_TIMEOUTS

在配置libstdc ++期间检查code> macro。如果检查成功结束 _GLIBCXX_HAS_GTHREADS 宏定义。并且< thread> 内容可用于 -std = c ++ 0x



libstdc ++确实需要 _POSIX_TIMEOUTS eg在 std :: timed_mutex 类实现中(见< mutex> 标题)。

总之,当GCC的gthreads或libstdc ++将实现pthread_mutex_timedlock()(以及其他)时,我认为< thread> )模拟,或者这个函数将在Mac OS X中实现。



或者在未来的C ++标准中可能会有一种方法来查询语言功能(例如,这个定时函数和类),并且可以在禁用此功能的情况下构建libstdc ++。不过,我对未来的标准并不十分熟悉,并对此功能有所怀疑。


I'm trying to compile some software I've been writing in Linux that uses some fancy new C++0x features on my Mac. I used MacPorts to install the gcc45 package, which gave me /opt/local/bin/g++-mp-4.5, however this compiler doesn't want to compile anything in <thread>. Eg I try to compile:

//test.cpp
#include <thread>

int main()
{
std::thread x;
return 0;
}

and get:

bash-3.2$ /opt/local/bin/g++-mp-4.5 -std=c++0x test.cpp 
test.cpp: In function 'int main()':
test.cpp:5:2: error: 'thread' is not a member of 'std'
test.cpp:5:14: error: expected ';' before 'x'

A quick look in /opt/local/include/gcc45/c++/thread shows that the std::thread class is defined, but is guarded by the following:

#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)

Again, this works perfectly on my Ubuntu machine, so what's the proper way to enable the c++0x <thread> library under the MacPorts version of g++ 4.5 (g++-mp-4.5)? Failing that, is there anything I need to know (configure flags, etc.) before I go about compiling gcc 4.5 myself?

Update: It doesn't look like the SO community knows much about this, so maybe it's time to go a little closer to the developers. Does anyone know of an official mailing list I could forward this question to? Are there any etiquette tips to help me get an answer?

Update 2: I asked SO for another temporary solution here, and so I'm now just substituting the boost::thread libraries for the std ones. Unfortunately, there is no boost::future so this isn't quite a full solution yet. Any help would still be greatly appreciated.

解决方案

Actually <thread> library doesn't work under Mac OS X because pthreads here don't have some functions with timeouts (e.g. pthread_mutex_timedlock()). Availability of this functions have to be checked using _POSIX_TIMEOUTS macro but it's defined to -1 in Mac OS X 10.4, 10.5 and 10.6 (I don't know what's about 10.7) and this functions are really absent in pthread.h.

The _POSIX_TIMEOUTS macro is checked during the configuration of libstdc++. If the check ends successfully _GLIBCXX_HAS_GTHREADS macro becomes defined. And <thread> contents become available with -std=c++0x.

libstdc++ really needs _POSIX_TIMEOUTS e.g. in std::timed_mutex class implementation (see <mutex> header).

To summarize, I think that <thread> would become available on Mac OS X when GCC's gthreads or libstdc++ will implement pthread_mutex_timedlock() (and others) emulation or when this functions will be implemented in Mac OS X.

Or maybe there would be a way in the future C++ standard to query for language features (e.g. this timed functions and classes) and it will be possible to build libstdc++ with this features disabled. However I'm not very familiar with the future standard and have doubts about that feature.

这篇关于std ::线程在MacPorts gcc4.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆