c++ - Ubuntu 13.10 上的 std::promise<T>::set_value() 以 "unknown error -1"(std::system_error) 结尾

标签 c++ ubuntu g++ promise future

以下 cpp 代码无法在使用 g++-4.8 或 g++-4.7 的 Ubuntu 13.10 上运行。我不知道如何解决这个问题。似乎在较旧的 Ubuntu 版本(例如 13.04)上,下面的代码可以正常工作。

代码

#include <future>
#include <iostream>

int main(int argc, char** argv) 
{
    int step = 0;
    std::cout << "step " << ++step << std::endl;

    std::promise<int> promise;
    std::cout << "step " << ++step << std::endl;

    try
    {
        promise.set_value(42);
        std::cout << "step " << ++step << std::endl;
    }
    catch (const std::system_error& ex)
    {
        std::cout << "Exception: " << ex.what() << "\n";
    }
}

构建并运行

g++ promise_test.cpp -o promise_test -pthread -std=c++11 && ./promise_test

输出

step 1
step 2
Exception: Unknown error -1

最佳答案

bug report .提供的解决方法是 -Wl,--no-as-needed。看这个other question .

关于c++ - Ubuntu 13.10 上的 std::promise<T>::set_value() 以 "unknown error -1"(std::system_error) 结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21138653/

相关文章:

python - wxPython - Ubuntu 上的 "Uknown accel modifier: num/numpad"

php - 更改 php 错误报告以仅隐藏特定站点的警告

c++ - 如何将 gcc 警告转储为结构化格式?

c++ - 有人可以向我解释这是未定义的行为吗?

c++ - UTF-8 字符的预处理器粘贴在 g++ 中执行 'not give a valid preprocessing token'

c++ - 使用vector时出错:what():vector::_ M_range_check

c++ - DirectX 程序在窗口模式下销毁时抛出异常

c++ - 访问 unordered_maps 作为指针

ubuntu - 在 Ubuntu 上安装 matplotlib vn 1.2 和 Basemap

c++ - 如何在 C++ 中按范围连接多个分隔符?