我正在尝试编译一些我在 Linux 中编写的软件,这些软件在我的 Mac 上使用了一些奇特的新 C++0x 功能。我使用 MacPorts 安装 gcc45 软件包,它给了我 /opt/local/bin/g++-mp-4.5,但是这个编译器不想编译
中的任何内容。例如,我尝试编译:
//test.cpp
#include <thread>
int main()
{
std::thread x;
return 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' is not a member of 'std'
test.cpp:5:14: error: expected ';' before 'x'
快速查看 /opt/local/include/gcc45/c++/thread 显示 std::thread 类已定义,但受以下内容保护:
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
再次,这在我的Ubuntu 机器,那么在 MacPorts 版本的 g++ 4.5 (g++-mp-4.5) 下启用 c++0x
库的正确方法是什么?如果做不到这一点,在我自己编译 gcc 4.5 之前,我需要知道什么(配置标志等)吗?
更新:
看起来 SO 社区对此了解不多,所以也许是时候更接近开发人员了。有谁知道我可以将此问题转发到的官方邮件列表吗?有什么礼仪提示可以帮助我得到答案吗?
更新2:
我要求另一个临时解决方案这里,所以我现在只是用 boost::thread 库替换 std 库。不幸的是,没有 boost::future 所以这还不是一个完整的解决方案。任何帮助仍然将不胜感激。
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.
发布评论
评论(2)
实际上
库在Mac OS X下不起作用,因为这里的pthreads没有一些带有超时的函数(例如pthread_mutex_timedlock())。必须使用检查此功能的可用性>_POSIX_TIMEOUTS
宏,但在 Mac OS X 10.4、10.5 和 10.6 中它被定义为-1
(我不知道 10.7 是什么),并且这个函数在 pthread 中确实不存在.h。在 libstdc++ 配置期间检查
_POSIX_TIMEOUTS
宏。如果检查成功结束,_GLIBCXX_HAS_GTHREADS
宏将被定义。并且
内容可通过-std=c++0x
使用。libstdc++ 确实需要
_POSIX_TIMEOUTS
例如在std::timed_mutex
类实现中(参见
标头)。总而言之,我认为当 GCC 的 gthreads 或 libstdc++ 将实现 pthread_mutex_timedlock() (和其他)模拟或在 Mac OS X 中实现此函数时,
将在 Mac OS X 上可用 或者,未来的 C++ 标准中可能会有一种方法来查询语言功能(例如,定时函数和类),并且可以在禁用此功能的情况下构建 libstdc++。但是我对未来的标准不太熟悉,并且对该功能存有疑问。
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 inpthread.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. instd::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.
更新 - gcc4.7 现在允许在 OS X 上编译:参见此处
Update - gcc4.7 now allows compilation of on OS X: See here