首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >标准C++库标头中的泛型“在此范围内未声明”错误

标准C++库标头中的泛型“在此范围内未声明”错误
EN

Stack Overflow用户
提问于 2021-07-07 09:08:14
回答 1查看 1.1K关注 0票数 1

最近,我无意中遇到了“在此范围内未声明”的多次错误,如下所示:

代码语言:javascript
运行
复制
/usr/include/c++/9/ext/string_conversions.h:84:25: error: ‘ERANGE’ was not declared in this scope
   84 |       else if (errno == ERANGE
      |                         ^~~~~~
In file included from /usr/include/c++/9/system_error:39,
                 from /usr/include/c++/9/bits/ios_base.h:46,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/fstream:38,
                 from myproject/main.cpp:3:
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h: At global scope:
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:42:40: error: ‘EAFNOSUPPORT’ was not declared in this scope
   42 |       address_family_not_supported =   EAFNOSUPPORT,
      |                                        ^~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:43:28: error: ‘EADDRINUSE’ was not declared in this scope
   43 |       address_in_use =     EADDRINUSE,
      |                            ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:44:34: error: ‘EADDRNOTAVAIL’ was not declared in this scope
   44 |       address_not_available =    EADDRNOTAVAIL,
      |                                  ^~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:45:30: error: ‘EISCONN’ was not declared in this scope
   45 |       already_connected =    EISCONN,
      |                              ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:46:35: error: ‘E2BIG’ was not declared in this scope
   46 |       argument_list_too_long =    E2BIG,
      |                                   ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:47:35: error: ‘EDOM’ was not declared in this scope
   47 |       argument_out_of_domain =    EDOM,
      |                                   ^~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:48:25: error: ‘EFAULT’ was not declared in this scope
   48 |       bad_address =     EFAULT,
      |                         ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:49:32: error: ‘EBADF’ was not declared in this scope
   49 |       bad_file_descriptor =    EBADF,
      |                                ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:52:25: error: ‘EBADMSG’ was not declared in this scope
   52 |       bad_message =     EBADMSG,
      |                         ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:55:25: error: ‘EPIPE’ was not declared in this scope
   55 |       broken_pipe =     EPIPE,
      |                         ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:56:31: error: ‘ECONNABORTED’ was not declared in this scope
   56 |       connection_aborted =    ECONNABORTED,
      |                               ^~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:57:42: error: ‘EALREADY’ was not declared in this scope
   57 |       connection_already_in_progress =   EALREADY,
      |                                          ^~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:58:31: error: ‘ECONNREFUSED’ was not declared in this scope
   58 |       connection_refused =    ECONNREFUSED,
      |                               ^~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:59:29: error: ‘ECONNRESET’ was not declared in this scope
   59 |       connection_reset =    ECONNRESET,
      |                             ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:60:30: error: ‘EXDEV’ was not declared in this scope
   60 |       cross_device_link =    EXDEV,
      |                              ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:61:40: error: ‘EDESTADDRREQ’ was not declared in this scope
   61 |       destination_address_required =   EDESTADDRREQ,
      |                                        ^~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:62:35: error: ‘EBUSY’ was not declared in this scope
   62 |       device_or_resource_busy =   EBUSY,
      |                                   ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:63:32: error: ‘ENOTEMPTY’ was not declared in this scope
   63 |       directory_not_empty =    ENOTEMPTY,
      |                                ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:64:35: error: ‘ENOEXEC’ was not declared in this scope
   64 |       executable_format_error =   ENOEXEC,
      |                                   ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:65:32: error: ‘EEXIST’ was not declared in this scope
   65 |       file_exists =            EEXIST,
      |                                ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:66:28: error: ‘EFBIG’ was not declared in this scope
   66 |       file_too_large =     EFBIG,
      |                            ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:67:30: error: ‘ENAMETOOLONG’ was not declared in this scope
   67 |       filename_too_long =    ENAMETOOLONG,
      |                              ^~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:68:35: error: ‘ENOSYS’ was not declared in this scope
   68 |       function_not_supported =    ENOSYS,
      |                                   ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:69:29: error: ‘EHOSTUNREACH’ was not declared in this scope
   69 |       host_unreachable =    EHOSTUNREACH,
      |                             ^~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:72:31: error: ‘EIDRM’ was not declared in this scope
   72 |       identifier_removed =    EIDRM,
      |                               ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:75:34: error: ‘EILSEQ’ was not declared in this scope
   75 |       illegal_byte_sequence =    EILSEQ,
      |                                  ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:76:45: error: ‘ENOTTY’ was not declared in this scope
   76 |       inappropriate_io_control_operation =  ENOTTY,
      |                                             ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:77:25: error: ‘EINTR’ was not declared in this scope
   77 |       interrupted =     EINTR,
      |                         ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:79:26: error: ‘ESPIPE’ was not declared in this scope
   79 |       invalid_seek =     ESPIPE,
      |                          ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:80:22: error: ‘EIO’ was not declared in this scope
   80 |       io_error =     EIO,
      |                      ^~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:81:28: error: ‘EISDIR’ was not declared in this scope
   81 |       is_a_directory =     EISDIR,
      |                            ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:82:26: error: ‘EMSGSIZE’ was not declared in this scope
   82 |       message_size =     EMSGSIZE,
      |                          ^~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:83:26: error: ‘ENETDOWN’ was not declared in this scope
   83 |       network_down =     ENETDOWN,
      |                          ^~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:84:27: error: ‘ENETRESET’ was not declared in this scope
   84 |       network_reset =     ENETRESET,
      |                           ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:85:32: error: ‘ENETUNREACH’ was not declared in this scope
   85 |       network_unreachable =    ENETUNREACH,
      |                                ^~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:86:28: error: ‘ENOBUFS’ was not declared in this scope
   86 |       no_buffer_space =    ENOBUFS,
      |                            ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:87:29: error: ‘ECHILD’ was not declared in this scope
   87 |       no_child_process =    ECHILD,
      |                             ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:90:21: error: ‘ENOLINK’ was not declared in this scope
   90 |       no_link =     ENOLINK,
      |                     ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:93:30: error: ‘ENOLCK’ was not declared in this scope
   93 |       no_lock_available =    ENOLCK,
      |                              ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:96:33: error: ‘ENODATA’ was not declared in this scope
   96 |       no_message_available =    ENODATA,
      |                                 ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:99:24: error: ‘ENOMSG’ was not declared in this scope
   99 |       no_message =     ENOMSG,
      |                        ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:100:31: error: ‘ENOPROTOOPT’ was not declared in this scope
  100 |       no_protocol_option =    ENOPROTOOPT,
      |                               ^~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:101:31: error: ‘ENOSPC’ was not declared in this scope
  101 |       no_space_on_device =    ENOSPC,
      |                               ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:104:32: error: ‘ENOSR’ was not declared in this scope
  104 |       no_stream_resources =    ENOSR,
      |                                ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:107:37: error: ‘ENXIO’ was not declared in this scope
  107 |       no_such_device_or_address =   ENXIO,
      |                                     ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:108:28: error: ‘ENODEV’ was not declared in this scope
  108 |       no_such_device =     ENODEV,
      |                            ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:109:37: error: ‘ENOENT’ was not declared in this scope
  109 |       no_such_file_or_directory =   ENOENT,
      |                                     ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:110:28: error: ‘ESRCH’ was not declared in this scope
  110 |       no_such_process =    ESRCH,
      |                            ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:111:28: error: ‘ENOTDIR’ was not declared in this scope
  111 |       not_a_directory =    ENOTDIR,
      |                            ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:112:26: error: ‘ENOTSOCK’ was not declared in this scope
  112 |       not_a_socket =     ENOTSOCK,
      |                          ^~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:115:26: error: ‘ENOSTR’ was not declared in this scope
  115 |       not_a_stream =     ENOSTR,
      |                          ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:118:27: error: ‘ENOTCONN’ was not declared in this scope
  118 |       not_connected =     ENOTCONN,
      |                           ^~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:119:30: error: ‘ENOMEM’ was not declared in this scope
  119 |       not_enough_memory =    ENOMEM,
      |                              ^~~~~~
In file included from /usr/include/errno.h:28,
                 from /usr/include/c++/9/cerrno:42,
                 from /usr/include/c++/9/ext/string_conversions.h:44,
                 from /usr/include/c++/9/bits/basic_string.h:6493,
                 from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/fstream:38,
                 from myproject/main.cpp:3:
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:122:27: error: ‘EOPNOTSUPP’ was not declared in this scope; did you mean ‘ENOTSUP’?
  122 |       not_supported =     ENOTSUP,
      |                           ^~~~~~~
In file included from /usr/include/c++/9/system_error:39,
                 from /usr/include/c++/9/bits/ios_base.h:46,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/fstream:38,
                 from Pyfhel/Afhel/Afseal.cpp:34:
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:129:34: error: ‘EINPROGRESS’ was not declared in this scope
  129 |       operation_in_progress =    EINPROGRESS,
      |                                  ^~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:130:35: error: ‘EPERM’ was not declared in this scope
  130 |       operation_not_permitted =   EPERM,
      |                                   ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:131:35: error: ‘EOPNOTSUPP’ was not declared in this scope; did you mean ‘ENOTSUP’?
  131 |       operation_not_supported =   EOPNOTSUPP,
      |                                   ^~~~~~~~~~
      |                                   ENOTSUP
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:132:34: error: ‘EWOULDBLOCK’ was not declared in this scope
  132 |       operation_would_block =    EWOULDBLOCK,
      |                                  ^~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:138:30: error: ‘EACCES’ was not declared in this scope
  138 |       permission_denied =    EACCES,
      |                              ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:141:28: error: ‘EPROTO’ was not declared in this scope
  141 |       protocol_error =     EPROTO,
      |                            ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:144:35: error: ‘EPROTONOSUPPORT’ was not declared in this scope
  144 |       protocol_not_supported =    EPROTONOSUPPORT,
      |                                   ^~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:145:34: error: ‘EROFS’ was not declared in this scope; did you mean ‘EOF’?
  145 |       read_only_file_system =    EROFS,
      |                                  ^~~~~
      |                                  EOF
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:146:41: error: ‘EDEADLK’ was not declared in this scope
  146 |       resource_deadlock_would_occur =   EDEADLK,
      |                                         ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:147:42: error: ‘EAGAIN’ was not declared in this scope
  147 |       resource_unavailable_try_again =   EAGAIN,
      |                                          ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:148:32: error: ‘ERANGE’ was not declared in this scope
  148 |       result_out_of_range =    ERANGE,
      |                                ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:155:28: error: ‘ETIME’ was not declared in this scope
  155 |       stream_timeout =     ETIME,
      |                            ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:159:28: error: ‘ETXTBSY’ was not declared in this scope
  159 |       text_file_busy =     ETXTBSY,
      |                            ^~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:162:23: error: ‘ETIMEDOUT’ was not declared in this scope
  162 |       timed_out =     ETIMEDOUT,
      |                       ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:163:41: error: ‘ENFILE’ was not declared in this scope; did you mean FILE’?
  163 |       too_many_files_open_in_system =   ENFILE,
      |                                         ^~~~~~
      |                                         FILE
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:164:32: error: ‘EMFILE’ was not declared in this scope; did you mean FILE’?
  164 |       too_many_files_open =    EMFILE,
      |                                ^~~~~~
      |                                FILE
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:165:28: error: ‘EMLINK’ was not declared in this scope
  165 |       too_many_links =     EMLINK,
      |                            ^~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:166:41: error: ‘ELOOP’ was not declared in this scope
  166 |       too_many_symbolic_link_levels =   ELOOP,
      |                                         ^~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:169:28: error: ‘EOVERFLOW’ was not declared in this scope
  169 |       value_too_large =    EOVERFLOW,
      |                            ^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/9/bits/error_constants.h:172:32: error: ‘EPROTOTYPE’ was not declared in this scope
  172 |       wrong_protocol_type =    EPROTOTYPE
      |                                ^~~~~~~~~~
In file included from myproject/main.cpp:4:
/usr/include/c++/9/thread: In function ‘void std::this_thread::sleep_for(const std::chrono::duration<_Rep1, _Period1>&)’:
/usr/include/c++/9/thread:378:53: error: ‘EINTR’ was not declared in this scope
  378 |  while (::nanosleep(&__ts, &__ts) == -1 && errno == EINTR)
      |                                                     ^~~~~

产生于单个.cpp编译:

代码语言:javascript
运行
复制
gcc -Imyproject/include1 -Imyproject/include2 -Imyproject/include3 -c myproject/main.cpp -o myproject/main.o

.cpp文件并没有做什么特别的事情:

代码语言:javascript
运行
复制
// main.cpp
#include <iostream> /* Print in std::cout */
#include <fstream>      /* file management */
#include <thread>   /* memory pools, multithread*/
#include "myheader1.h"
int main(int argc, char** argv) {
    std::cout << "Have " << argc << " arguments:" << std::endl;
    for (int i = 0; i < argc; ++i) {
        std::cout << argv[i] << std::endl;
    }
}

myheader.h空的

造成这一错误的原因是什么,如何解决?

注意:抛出的所有错误行都属于标准库中的问题,切换到g++没有任何影响。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-07 09:14:42

由于我们非常确定我们没有有意地访问标准库,而且这不是C++版本的问题(已经尝试添加-std=c++17并与编译的args类似,但没有效果),因此此错误意味着我们意外地使用了标准的.h头。

造成这一错误的原因是什么?

include目录中至少有一个头文件(本例中为myproject/include1myproject/include2myproject/include3 )重载了C++ stdlib模块的名称,导致其中断。

如何解决这个问题?

删除冲突的头文件(如果您检测到的话),将您包含的所有头文件重命名为具有非标准名称(避免vector.hmemory.h和排序),或者只包括编译所需的文件和目录,忽略冲突的文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68283147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档