【问题标题】:‘struct in6_addr’ has no member named ‘s6_addr32’ with -ansi‘struct in6_addr’ 没有名为 ‘s6_addr32’ 且带有 -ansi 的成员
【发布时间】:2016-03-25 12:53:51
【问题描述】:

我在使用 no-asm -ansi 构建 OpenSSL 时遇到了一些编译错误。我发现了错误:

$ ./config no-asm -ansi
...
$ make
...
gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC
-DOPENSSLDIR="\"/usr/local/ssl\"" -DENGINESDIR="\"/usr/local/lib/engines\"" -Wall -O3
-pthread -m64 -DL_ENDIAN  -ansi -fPIC -Iinclude -I. -Icrypto/include -MMD -MF
crypto/bio/bss_dgram.d.tmp -MT crypto/bio/bss_dgram.o -c -o crypto/bio/bss_dgram.o
crypto/bio/bss_dgram.c
In file included from /usr/include/netdb.h:27:0,
                 from ./e_os.h:443,
                 from crypto/bio/bio_lcl.h:2,
                 from crypto/bio/bss_dgram.c:62:
crypto/bio/bss_dgram.c: In function ‘dgram_get_mtu_overhead’:
crypto/bio/bss_dgram.c:433:20: error: ‘const struct in6_addr’ has no member named ‘s6_addr32’
                 && IN6_IS_ADDR_V4MAPPED(&tmp_addr))
                    ^

我在/usr/include/linux/in6.h中找到了结构:

#if __UAPI_DEF_IN6_ADDR
struct in6_addr {
    union {
        __u8        u6_addr8[16];
#if __UAPI_DEF_IN6_ADDR_ALT
        __be16      u6_addr16[8];
        __be32      u6_addr32[4];
#endif
    } in6_u;
#define s6_addr         in6_u.u6_addr8
#if __UAPI_DEF_IN6_ADDR_ALT
#define s6_addr16       in6_u.u6_addr16
#define s6_addr32       in6_u.u6_addr32
#endif
};
#endif /* __UAPI_DEF_IN6_ADDR */

我不记得过去需要定义__UAPI_DEF_IN6_ADDR_ALT。搜索它会从内核的libc-compat.h 中显示以下内容,第 95 行左右(如果我解析正确的话):

#define __UAPI_DEF_IN6_ADDR             1
/* We unconditionally define the in6_addr macros and glibc must coordinate. */
#define __UAPI_DEF_IN6_ADDR_ALT         1
#define __UAPI_DEF_SOCKADDR_IN6         1
#define __UAPI_DEF_IPV6_MREQ            1
#define __UAPI_DEF_IPPROTO_V6           1
#define __UAPI_DEF_IPV6_OPTIONS         1
#define __UAPI_DEF_IN6_PKTINFO          1
#define __UAPI_DEF_IP6_MTUINFO          1

我应该如何继续定义替代符号?


系统是 Ubuntu 14.04 (x86_64):

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

GCC 是:

$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.

【问题讨论】:

  • 您是否考虑过针对 OpenSSL 提出问题?如果构建配置程序运行没有错误,那么您应该能够依赖构建成功,所以这肯定是一个真正的错误。这不仅是正确的做法,而且对票证的评论可能会产生解决方法或修复。
  • 报告提交至Issue #4480: Ubuntu 14 (x86_64): Compile errors and warnings when using "no-asm -ansi"。实际上,我现在更接近那个处理错误的人。

标签: c linux ipv6 ansi


【解决方案1】:

事实证明这很有趣...简而言之,我需要同时添加-ansi-D_DEFAULT_SOURCE=1。然而,-D_DEFAULT_SOURCE=1 有点撤销-ansi 试图完成的任务,因此需要对其进行控制。

首先,/usr/include/linux/in6.h 是错误的标题。我通过 struct in6_addr 的 grep 找到了它,并且没有跟踪需要完成的操作。

接下来...-D_DEFAULT_SOURCE=1间接来自/usr/include/netinet/in.h

#ifndef __USE_KERNEL_IPV6_DEFS
/* IPv6 address */
struct in6_addr
  {
    union
      {
    uint8_t __u6_addr8[16];
#ifdef __USE_MISC
    uint16_t __u6_addr16[8];
    uint32_t __u6_addr32[4];
#endif
      } __in6_u;
#define s6_addr         __in6_u.__u6_addr8
#ifdef __USE_MISC
# define s6_addr16      __in6_u.__u6_addr16
# define s6_addr32      __in6_u.__u6_addr32
#endif
  };
#endif /* !__USE_KERNEL_IPV6_DEFS */

手动启用__USE_MISC 不起作用。在/usr/include/features.h 中跟踪__USE_MISC 的内容:

/*
...
   __USE_MISC       Define things from 4.3BSD or System V Unix.
...
*/

#undef __USE_MISC
...

#if defined _DEFAULT_SOURCE
# define __USE_MISC 1
#endif

最后,来自/usr/include/features.h 的评论:

_DEFAULT_SOURCE The default set of features (taking precedence over __STRICT_ANSI__).

虽然_DEFAULT_SOURCE=1-ansi 不同,但影响可能仅限于受IN6_IS_ADDR_V4MAPPED 影响的一个源文件。即对于C源文件crypto/bio/bss_dgram.c

/* OpenSSL copyright ... */

#ifndef _DEFAULT_SOURCE
# define _DEFAULT_SOURCE 1
#endif

#include <stdio.h>
#include <errno.h>
#include <netinet/in.h>
...

摆弄__USE_KERNEL_IPV6_DEFS 让事情变得更糟。我相信它启用了/usr/include/linux/in6.h,它的成员名称与&lt;netinet/in.h&gt; 相似(但完全不同)。

【讨论】:

    猜你喜欢
    • 2014-12-26
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 2010-09-17
    相关资源
    最近更新 更多