V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hhhhhh123
V2EX  ›  C

ubuntu /usr/include/c++/11/ 下的文件报错

  •  
  •   hhhhhh123 · 2022-07-27 18:08:24 +08:00 · 1493 次点击
    这是一个创建于 631 天前的主题,其中的信息可能已经有所发展或是发生改变。

    主要是这几个错误

    /usr/include/c++/11/bits/uniform_int_dist.h:284:71: error: call to non-‘constexpr’ function ‘static uint64_t omp::XoroShiro128Plus::min()’ 284 | constexpr __uctype __urngmin = _UniformRandomBitGenerator::min();

    /usr/include/c++/11/bits/uniform_int_dist.h:285:71: error: call to non-‘constexpr’ function ‘static uint64_t omp::XoroShiro128Plus::max()’ 285 | constexpr __uctype __urngmax = _UniformRandomBitGenerator::max();

    /usr/include/c++/11/bits/uniform_int_dist.h:286:34: error: non-constant condition for static assertion
    286 | static_assert( __urngmin < __urngmax,

    下面是完整信息 g++ -O3 -std=c++11 -Wall -Wpedantic -pthread -c -o omp/CombinedRange.o omp/CombinedRange.cpp
    In file included from /usr/include/c++/11/bits/stl_algo.h:66,
    from /usr/include/c++/11/algorithm:62,
    from omp/CombinedRange.cpp:4:
    /usr/include/c++/11/bits/uniform_int_dist.h: In instantiation of ‘std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomBitGenerator&, const std::uniform_int_distribution<_IntType>::param_type&) [with _UniformRandomBitGenerator = omp::XoroShiro128Plus; _IntType = long unsigned int; std::uniform_int_distribution<_IntType>::result_type = long unsigned int]’:
    /usr/include/c++/11/bits/stl_algo.h:3791:35: required from ‘void std::shuffle(_RAIter, _RAIter, _UGenerator&&) [with _RAIter = __gnu_cxx::__normal_iterator<omp::CombinedRange::Combo*, std::vector<omp::CombinedRange::Combo, omp::AlignedAllocatoromp::CombinedRange::Combo > >; _UGenerator = omp::XoroShiro128Plus&]’
    omp/CombinedRange.cpp:101:17: required from here
    /usr/include/c++/11/bits/uniform_int_dist.h:284:71: error: call to non-‘constexpr’ function ‘static uint64_t omp::XoroShiro128Plus::min()’
    284 | constexpr __uctype __urngmin = _UniformRandomBitGenerator::min();
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
    In file included from omp/CombinedRange.cpp:3:
    omp/Random.h:32:21: note: ‘static uint64_t omp::XoroShiro128Plus::min()’ declared here 32 | static uint64_t min() | ^ In file included from /usr/include/c++/11/bits/stl_algo.h:66, from /usr/include/c++/11/algorithm:62, from omp/CombinedRange.cpp:4: /usr/include/c++/11/bits/uniform_int_dist.h:285:71: error: call to non-‘constexpr’ function ‘static uint64_t omp::XoroShiro128Plus::max()’ 285 | constexpr __uctype __urngmax = _UniformRandomBitGenerator::max(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ In file included from omp/CombinedRange.cpp:3: omp/Random.h:37:21: note: ‘static uint64_t omp::XoroShiro128Plus::max()’ declared here 37 | static uint64_t max() | ^ In file included from /usr/include/c++/11/bits/stl_algo.h:66, from /usr/include/c++/11/algorithm:62, from omp/CombinedRange.cpp:4: /usr/include/c++/11/bits/uniform_int_dist.h:286:34: error: non-constant condition for static assertion 286 | static_assert( __urngmin < __urngmax, | ~~~~~~^~~~~~~~~ make: *** [<builtin>: omp/CombinedRange.o] Error 1

    14 条回复    2022-07-29 10:59:55 +08:00
    elfive
        1
    elfive  
       2022-07-27 18:43:07 +08:00 via iPhone
    1. 把 min()和 max()函数里调用_UniformRandomBitGenerator::min()和_UniformRandomBitGenerator::max();的定义去掉 constexpr 修饰。

    2. static_assert 改为 assert
    hhhhhh123
        2
    hhhhhh123  
    OP
       2022-07-28 09:36:37 +08:00
    @elfive 我是要 修改 /usr/include/c++/11/bits/uniform_int_dist 这些底层文件是吗? 修改后 会对其他代码编译什么的受影响吗
    hhhhhh123
        3
    hhhhhh123  
    OP
       2022-07-28 09:45:44 +08:00
    @elfive 方法 1 成功解决一部分,但是方法 2 好像不行还是报错了 出现了两个新的错误
    In file included from /usr/include/c++/11/bits/stl_algo.h:66,
    from /usr/include/c++/11/algorithm:62,
    from omp/CombinedRange.cpp:4:
    /usr/include/c++/11/bits/uniform_int_dist.h:286:96: error: macro "assert" passed 2 arguments, but takes just 1
    286 | assert( __urngmin < __urngmax, "Uniform random bit generator must define min() < max()");


    niform_int_distribution<_IntType>::param_type&)’:
    /usr/include/c++/11/bits/uniform_int_dist.h:286:9: error: ‘assert’ was not declared in this scope
    286 | assert( __urngmin < __urngmax, "Uniform random bit generator must define min() < max()");
    hhhhhh123
        4
    hhhhhh123  
    OP
       2022-07-28 09:46:35 +08:00
    @elfive static_assert( __urngmin < __urngmax, "Uniform random bit generator must define min() < max()");

    我删除 static_ 后 就是上面的报错
    elfive
        5
    elfive  
       2022-07-28 10:26:28 +08:00 via iPhone
    @hhhhhh123 ……
    static_assert 是编译期断言,后面第二个参数是断言失败的输出错误信息……
    assert 是运行时断言,只有一个参数,你删除第二个参数不就好了……
    hhhhhh123
        6
    hhhhhh123  
    OP
       2022-07-28 13:51:43 +08:00
    @elfive 好像还是不行, 弄了就出新的一堆错误
    hhhhhh123
        7
    hhhhhh123  
    OP
       2022-07-28 13:54:12 +08:00
    @elfive 这是修改后的
    __uctype __urngmin = _UniformRandomBitGenerator::min();
    __uctype __urngmax = _UniformRandomBitGenerator::max();
    assert( __urngmin < __urngmax);

    报错信息变多了....

    g++ -O3 -std=c++11 -Wall -Wpedantic -pthread -c -o omp/EquityCalculator.o omp/EquityCalculator.cpp
    In file included from omp/EquityCalculator.cpp:1:
    omp/EquityCalculator.h:76:21: error: ‘std::function’ has not been declared
    76 | std::function<void(const Results&)> callback = nullptr,
    | ^~~~~~~~
    omp/EquityCalculator.h:76:29: error: expected ‘,’ or ‘...’ before ‘<’ token
    76 | std::function<void(const Results&)> callback = nullptr,
    | ^
    omp/EquityCalculator.h:202:10: error: ‘function’ in namespace ‘std’ does not name a template type
    202 | std::function<void(const Results& results)> mCallback;
    | ^~~~~~~~
    omp/EquityCalculator.h:15:1: note: ‘std::function’ is defined in header ‘<functional>’; did you forget to ‘#include <functional>’?
    14 | #include <unordered_map>
    +++ |+#include <functional>
    15 | #include <array>
    omp/EquityCalculator.h:76:16: error: default argument missing for parameter 6 of ‘bool omp::EquityCalculator::start(const std::vector<omp::CardRange>&, uint64_t, uint64_t, bool, double, int)’
    76 | std::function<void(const Results&)> callback = nullptr,
    | ^~~~~~~~~~~~~
    omp/EquityCalculator.h:74:67: note: ...following parameter 2 which has a default argument
    74 | bool start(const std::vector<CardRange>& handRanges, uint64_t boardCards = 0, uint64_t deadCards = 0,
    | ~~~~~~~~~^~~~~~~~~~~~~~
    omp/EquityCalculator.cpp:14:74: error: ‘std::function’ has not been declared
    14 | bool enumerateAll, double stdevTarget, std::function<void(const Results&)> callback,
    | ^~~~~~~~
    omp/EquityCalculator.cpp:14:82: error: expected ‘,’ or ‘...’ before ‘<’ token
    14 | bool enumerateAll, double stdevTarget, std::function<void(const Results&)> callback,
    | ^
    omp/EquityCalculator.cpp: In member function ‘bool omp::EquityCalculator::start(const std::vector<omp::CardRange>&, uint64_t, uint64_t, bool, double, int)’:
    omp/EquityCalculator.cpp:47:5: error: ‘mCallback’ was not declared in this scope
    47 | mCallback = callback;
    | ^~~~~~~~~
    omp/EquityCalculator.cpp:47:17: error: ‘callback’ was not declared in this scope; did you mean ‘calloc’?
    47 | mCallback = callback;
    | ^~~~~~~~
    | calloc
    omp/EquityCalculator.cpp:48:23: error: ‘updateInterval’ was not declared in this scope; did you mean ‘mUpdateInterval’?
    48 | mUpdateInterval = updateInterval;
    | ^~~~~~~~~~~~~~
    | mUpdateInterval
    omp/EquityCalculator.cpp:51:9: error: ‘threadCount’ was not declared in this scope
    51 | if (threadCount == 0)
    | ^~~~~~~~~~~
    omp/EquityCalculator.cpp:53:26: error: ‘threadCount’ was not declared in this scope
    53 | mUnfinishedThreads = threadCount;
    | ^~~~~~~~~~~
    omp/EquityCalculator.cpp: In member function ‘void omp::EquityCalculator::updateResults(const omp::EquityCalculator::BatchResults&, bool)’:
    omp/EquityCalculator.cpp:740:13: error: ‘mCallback’ was not declared in this scope
    740 | if (mCallback)
    | ^~~~~~~~~
    make: *** [<builtin>: omp/EquityCalculator.o] Error 1
    elfive
        8
    elfive  
       2022-07-28 15:29:59 +08:00 via iPhone
    @hhhhhh123 输出信息都告诉你了 std::function 没有定义,也提示你是不是忘记了#include <functional>头文件……

    你得去把 C/C++基础打牢点……
    hhhhhh123
        9
    hhhhhh123  
    OP
       2022-07-28 15:48:21 +08:00
    @elfive 我不是 c++开发,是 python 开发
    hhhhhh123
        10
    hhhhhh123  
    OP
       2022-07-28 15:51:57 +08:00
    @elfive 在上面写了
    #ifndef _GLIBCXX_BITS_UNIFORM_INT_DIST_H
    #define _GLIBCXX_BITS_UNIFORM_INT_DIST_H

    #include <type_traits>
    #include <ext/numeric_traits.h>
    #if __cplusplus > 201703L
    # include <concepts>
    #endif
    #include <bits/concept_check.h> // __glibcxx_function_requires
    #include <functional>


    但是错误好像还是这个
    hhhhhh123
        11
    hhhhhh123  
    OP
       2022-07-28 15:53:21 +08:00
    @elfive

    In file included from omp/EquityCalculator.cpp:1:
    omp/EquityCalculator.h:76:21: error: ‘std::function’ has not been declared
    76 | std::function<void(const Results&)> callback = nullptr,
    | ^~~~~~~~
    omp/EquityCalculator.h:76:29: error: expected ‘,’ or ‘...’ before ‘<’ token
    76 | std::function<void(const Results&)> callback = nullptr,
    | ^
    omp/EquityCalculator.h:202:10: error: ‘function’ in namespace ‘std’ does not name a template type
    202 | std::function<void(const Results& results)> mCallback;
    | ^~~~~~~~
    omp/EquityCalculator.h:15:1: note: ‘std::function’ is defined in header ‘<functional>’; did you forget to ‘#include <functional>’?
    14 | #include <unordered_map>
    +++ |+#include <functional>
    15 | #include <array>
    omp/EquityCalculator.h:76:16: error: default argument missing for parameter 6 of ‘bool omp::EquityCalculator::start(const std::vector<omp::CardRange>&, uint64_t, uint64_t, bool, double, int)’
    76 | std::function<void(const Results&)> callback = nullptr,
    | ^~~~~~~~~~~~~
    omp/EquityCalculator.h:74:67: note: ...following parameter 2 which has a default argument
    74 | bool start(const std::vector<CardRange>& handRanges, uint64_t boardCards = 0, uint64_t deadCards = 0,
    | ~~~~~~~~~^~~~~~~~~~~~~~
    omp/EquityCalculator.cpp:13:6: error: no declaration matches ‘bool omp::EquityCalculator::start(const std::vector<omp::CardRange>&, uint64_t, uint64_t, bool, double, std::function<void(const omp::EquityCalculator::Results&)>, double, unsigned int)’
    13 | bool EquityCalculator::start(const std::vector<CardRange>& handRanges, uint64_t boardCards, uint64_t deadCards,
    | ^~~~~~~~~~~~~~~~
    In file included from omp/EquityCalculator.cpp:1:
    omp/EquityCalculator.h:74:10: note: candidate is: ‘bool omp::EquityCalculator::start(const std::vector<omp::CardRange>&, uint64_t, uint64_t, bool, double, int)’
    74 | bool start(const std::vector<CardRange>& handRanges, uint64_t boardCards = 0, uint64_t deadCards = 0,
    | ^~~~~
    omp/EquityCalculator.h:22:7: note: ‘class omp::EquityCalculator’ defined here
    22 | class EquityCalculator
    | ^~~~~~~~~~~~~~~~
    omp/EquityCalculator.cpp: In member function ‘void omp::EquityCalculator::updateResults(const omp::EquityCalculator::BatchResults&, bool)’:
    omp/EquityCalculator.cpp:740:13: error: ‘mCallback’ was not declared in this scope
    740 | if (mCallback)
    | ^~~~~~~~~
    make: *** [<builtin>: omp/EquityCalculator.o] Error 1
    elfive
        12
    elfive  
       2022-07-29 05:38:49 +08:00 via iPhone
    @hhhhhh123 这么跟你说吧,你用的这个库或者可能是别人写的代码,感觉应该不是 c++11 标准下的东西。
    做法也无非是
    1. 要么用新的 gcc ,并且使用编译参数设置适合的 c++标准;
    2. 要么更换旧版本的库,满足 c++11 标准或者你指定的某一 c++标准。

    这些问题再这么弄下去,真不知道会不会弄得完(清零)
    hhhhhh123
        13
    hhhhhh123  
    OP
       2022-07-29 09:18:21 +08:00
    @elfive gcc 都是最新的。 这不是源码吗? 应该是官方的吧
    hhhhhh123
        14
    hhhhhh123  
    OP
       2022-07-29 10:59:55 +08:00
    @elfive 请教一下,win 本地 make 能 ok , 但是在服务器就找不到一个文件, 这是没有指定路径还是啥?
    main.cpp:1:10: fatal error: omp/EquityCalculator.h: No such file or directory
    1 | #include <omp/EquityCalculator.h>
    | ^~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3073 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:41 · PVG 22:41 · LAX 07:41 · JFK 10:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.