这段代码有效吗,还是我的编译器坏了?
#include <future>
#include <iostream>
int main() {
std::cout << "doing the test" << std::endl;
std::promise<bool> mypromise;
std::future<bool> myfuture = mypromise.get_future();
mypromise.set_value(true);
bool result = myfuture.get();
std::cout << "success, result is " << result << std::endl;
return 0;
}
这是输出:
$ g++-mp-4.8 -std=c++11 test.cpp
$ ./a.out
doing the test
Segmentation fault: 11
$
我正在使用 g++-mp-4.8,这是来自 macports 的 gcc 4.8。
我要疯了吗?
动态链接器可能会将您的程序链接到旧版本libstdc++
,其中的一个/opt/local/lib/libstdc++.6.dylib
由于您使用 GCC 4.8 进行编译,因此您需要使用新的libstdc++
GCC 4.8 附带的,这可能是/opt/local/lib/gcc48/libstdc++.6.dylib
您应该检查是否/opt/local/lib/libstdc++.6.dylib
是 GCC 4.8 附带的库,如果不是,请使用正确的库。
您可以通过多种方式控制它,最简单的(但不一定是最好的)是运行:
export DYLD_LIBRARY_PATH=/opt/local/lib/gcc48/
./a.out
See http://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.how_to_set_paths http://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.how_to_set_paths and http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dynamic_or_shared.html#manual.intro.using.linkage.dynamic http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dynamic_or_shared.html#manual.intro.using.linkage.dynamic其他信息(并非特定于 Mac OS X)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)