RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1339215
Accepted
AVK
AVK
Asked:2022-03-17 18:42:18 +0000 UTC2022-03-17 18:42:18 +0000 UTC 2022-03-17 18:42:18 +0000 UTC

编译在 mingw 中使用 Boost Multiprecision 的程序时出错

  • 772

我需要具有任意精度的计算,因此我决定使用 Boost Multiprecision。我下载了 Boost 1.77 并尝试使用 mingw 编译这个程序:

#include <iostream>
#include <boost/multiprecision/cpp_bin_float.hpp>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

这个程序没有编译。编译器报错:

C:\include\boost\math\special_functions\detail\bernoulli_details.hpp|559|错误:命名空间'std'中的'mutex'没有命名类型| C:\include\boost\math\special_functions\detail\bernoulli_details.hpp|21|注意:'std::mutex' 定义在头文件''中;你忘了'#include mutex'吗?

等等。看着 bernoulli_details.hpp 我看到了这个:

#ifdef BOOST_HAS_THREADS
std::mutex m_mutex;
atomic_counter_type m_counter, m_current_precision;
#else
int m_counter;
int m_current_precision;
#endif // BOOST_HAS_THREADS

有点惊讶的是,理论上应该计算伯努利数的文件说这个,我决定我需要找到配置文件并删除#define BOOST_HAS_THREADS. 我不需要多线程。顺便说一句,我也不需要伯努利数。正如您可能猜到的那样,我失败了……BOOST_HAS_THREADS定义了 18 个文件。其中一些是平台配置文件,其余的是来自各种 Boost 数学库的文件,其中该宏被无条件地重新定义。修改所有这些文件可能不值得,而且没有任何意义。我再次感到惊讶,我想问:是否有可能以某种方式在 mingw 中编译我的程序,还是放弃这个想法并使用 Visual Studio 更好?理想情况下,我想以某种方式禁用多线程,因为对此有一个宏并且它在 mingw 中被破坏了。

c++
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    HolyBlackCat
    2022-03-17T18:56:35Z2022-03-17T18:56:35Z

    多线程......在mingw-w64中......坏了

    没有什么是坏的。在普通的 MinGW(不是 w64)中,它似乎还没有被提出,但在 MinGW-w64 中一切都应该工作。

    无需用手在助推器中四处寻找。你来做这件事:

    • 拆除您拥有的所有版本的 MinGW。
    • 安装 MSYS2 并从那里安装 MinGW,如此处所述。
    • 从那里,使用命令进行升压pacman -S mingw-w64-x86_64-boost
    • 然后一切都应该开箱即用。
    • 3
  2. Pak Uula
    2022-03-17T19:49:54Z2022-03-17T19:49:54Z

    您需要使用 posix 多线程安装 MinGW。

    PS C:\Users\User\tmp\try-boost> g++.exe .\some.c++ -I .\boost_1_77_0\
    In file included from .\boost_1_77_0/boost/multiprecision/traits/is_variable_precision.hpp:9,
                     from .\boost_1_77_0/boost/multiprecision/detail/precision.hpp:9,
                     from .\boost_1_77_0/boost/multiprecision/number.hpp:11,
                     from .\boost_1_77_0/boost/multiprecision/cpp_int.hpp:13,
                     from .\boost_1_77_0/boost/multiprecision/cpp_bin_float.hpp:9,
                     from .\some.c++:2:
    .\boost_1_77_0/boost/multiprecision/detail/number_base.hpp:92:21: warning: thread_local on mingw is broken, please use MSys mingw gcc-9 or later, see https://sourceforge.net/p/mingw-w64/bugs/527/
     #pragma GCC warning "thread_local on mingw is broken, please use MSys mingw gcc-9 or later, see https://sourceforge.net/p/mingw-w64/bugs/527/"
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    这是成功构建程序的 mingw-w64 变体的配置信息。

    PS C:\Users\User\tmp\try-boost> g++ -v
    Using built-in specs.
    COLLECT_GCC=D:\Software\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe
    COLLECT_LTO_WRAPPER=D:/Software/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
    Target: x86_64-w64-mingw32
    Configured with: ...
    Thread model: posix
    gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
    

    带有 win32 多线程的 mingw-w64 变体未定义std::mutex:

    PS C:\Users\User\tmp\try-boost> g++ -v
    Using built-in specs.
    COLLECT_GCC=D:\Software\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\g++.exe
    COLLECT_LTO_WRAPPER=D:/Software/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
    Target: x86_64-w64-mingw32
    Configured with: ...
    Thread model: win32
    gcc version 8.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)
    
    PS C:\Users\User\tmp\try-boost> g++ .\some.c++ -I .\boost_1_77_0\
    In file included from .\boost_1_77_0/boost/multiprecision/traits/is_variable_precision.hpp:9,
                     from .\boost_1_77_0/boost/multiprecision/detail/precision.hpp:9,
                     from .\boost_1_77_0/boost/multiprecision/number.hpp:11,
                     from .\boost_1_77_0/boost/multiprecision/cpp_int.hpp:13,
                     from .\boost_1_77_0/boost/multiprecision/cpp_bin_float.hpp:9,
                     from .\some.c++:2:
    .\boost_1_77_0/boost/multiprecision/detail/number_base.hpp:92:21: warning: thread_local on mingw is broken, please use MSys mingw gcc-9 or later, see https://sourceforge.net/p/mingw-w64/bugs/527/
     #pragma GCC warning "thread_local on mingw is broken, please use MSys mingw gcc-9 or later, see https://sourceforge.net/p/mingw-w64/bugs/527/"
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from .\boost_1_77_0/boost/math/special_functions/bernoulli.hpp:16,
                     from .\boost_1_77_0/boost/math/special_functions/gamma.hpp:35,
                     from .\boost_1_77_0/boost/multiprecision/cpp_bin_float.hpp:24,
                     from .\some.c++:2:
    .\boost_1_77_0/boost/math/special_functions/detail/bernoulli_details.hpp:559:9: error: 'mutex' in namespace 'std' does not name a type
        std::mutex m_mutex;
             ^~~~~
    
    • 1

相关问题

  • 编译器和模板处理

  • 指针。找到最小数量

  • C++,关于枚举类对象初始化的问题

  • 函数中的二维数组

  • 无法使用默认构造函数创建类对象

  • C++ 和循环依赖

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5