且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用mingw编译websocketpp示例代码时未定义对`std :: errc :: operation_canceled`的引用

更新时间:2022-04-30 23:18:35

我已经将其报告为mingw-w64中的错误

I have reported this as a bug at mingw-w64

mingw-w64编译器不符合C ++ 11,没有定义此错误代码, 但是人们已经知道了,这是故意的. (尽管随便我不 知道为什么他们无法修复它.)

The mingw-w64 compiler is C++11 non-compliant in not defining this error-code, but the folks already know that and it's deliberate. (Although offhand I don't know why they couldn't fix it.)

相关的头文件是:

<toochain_dir>/mingw64/x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32/bits/error_constants.h

这是enum class std::errc的定义:

// Most of the commented-out error codes are socket-related and could be
// replaced by Winsock WSA-prefixed equivalents.
  enum class errc
    {
//    address_family_not_supported =        EAFNOSUPPORT,
//    address_in_use =              EADDRINUSE,
//    address_not_available =           EADDRNOTAVAIL,
//    already_connected =           EISCONN,
      argument_list_too_long =          E2BIG,
      argument_out_of_domain =          EDOM,
      bad_address =                 EFAULT,
      bad_file_descriptor =             EBADF,
//    bad_message =                 EBADMSG,
      broken_pipe =                 EPIPE,
//    connection_aborted =          ECONNABORTED,
//    connection_already_in_progress =      EALREADY,
//    connection_refused =          ECONNREFUSED,
//    connection_reset =            ECONNRESET,
//    cross_device_link =           EXDEV,
//    destination_address_required =        EDESTADDRREQ,
      device_or_resource_busy =         EBUSY,
      directory_not_empty =             ENOTEMPTY,
      executable_format_error =         ENOEXEC,
      file_exists =                     EEXIST,
      file_too_large =              EFBIG,
      filename_too_long =           ENAMETOOLONG,
      function_not_supported =          ENOSYS,
//    host_unreachable =            EHOSTUNREACH,
//    identifier_removed =          EIDRM,
      illegal_byte_sequence =           EILSEQ,
      inappropriate_io_control_operation =  ENOTTY,
      interrupted =                 EINTR,
      invalid_argument =            EINVAL,
      invalid_seek =                ESPIPE,
      io_error =                EIO,
      is_a_directory =              EISDIR,
//    message_size =                EMSGSIZE,
//    network_down =                ENETDOWN,
//    network_reset =               ENETRESET,
//    network_unreachable =             ENETUNREACH,
//    no_buffer_space =             ENOBUFS,
#ifdef _GLIBCXX_HAVE_ECHILD
      no_child_process =            ECHILD,
#endif
//    no_link =                 ENOLINK,
      no_lock_available =           ENOLCK,
//    no_message_available =            ENODATA,
//    no_message =              ENOMSG,
//    no_protocol_option =          ENOPROTOOPT,
#ifdef _GLIBCXX_HAVE_ENOSPC
      no_space_on_device =          ENOSPC,
#endif
//    no_stream_resources =             ENOSR,
      no_such_device_or_address =       ENXIO,
      no_such_device =              ENODEV,
      no_such_file_or_directory =       ENOENT,
      no_such_process =             ESRCH,
      not_a_directory =             ENOTDIR,
//    not_a_socket =                ENOTSOCK,
//    not_a_stream =                ENOSTR,
//    not_connected =               ENOTCONN,
      not_enough_memory =           ENOMEM,
#ifdef _GLIBCXX_HAVE_ENOTSUP
      not_supported =               ENOTSUP,
#endif
//    operation_canceled =          ECANCELED,
//    operation_in_progress =           EINPROGRESS,
#ifdef _GLIBCXX_HAVE_EPERM
      operation_not_permitted =         EPERM,
#endif
//    operation_not_supported =         EOPNOTSUPP,
#ifdef _GLIBCXX_HAVE_EWOULDBLOCK
      operation_would_block =           EWOULDBLOCK,
#endif
//    owner_dead =              EOWNERDEAD,
      permission_denied =           EACCES,
//    protocol_error =              EPROTO,
//    protocol_not_supported =          EPROTONOSUPPORT,
      read_only_file_system =           EROFS,
      resource_deadlock_would_occur =       EDEADLK,
      resource_unavailable_try_again =      EAGAIN,
      result_out_of_range =             ERANGE,
//    state_not_recoverable =           ENOTRECOVERABLE,
//    stream_timeout =              ETIME,
//    text_file_busy =              ETXTBSY,
#ifdef _GLIBCXX_HAVE_ETIMEDOUT
      timed_out =               ETIMEDOUT,
#endif
      too_many_files_open_in_system =       ENFILE,
      too_many_files_open =             EMFILE,
      too_many_links =              EMLINK
//    too_many_symbolic_link_levels =       ELOOP,
#ifdef _GLIBCXX_HAVE_EOVERFLOW
    ,
      value_too_large =             EOVERFLOW
#endif
//    wrong_protocol_type =             EPROTOTYPE
   };

您看到operation_canceled是其中之一.

根据此处的建议,您将需要使用winsock错误代码WSAECANCELLED, 在winerror.h中定义.如果您想要便携性,那么您当然需要 根据主机OS的编译时确定,使用此命令,而不使用std::errc::operation_canceled作为条件.

As suggested there, you will need to use the winsock error code WSAECANCELLED, defined in winerror.h. If you want portability, of course you'll need to make this use rather than std::errc::operation_canceled conditional upon compiletime determination of the host OS.