代码之家  ›  专栏  ›  技术社区  ›  criw

警告:“…”的声明在此函数外不可见[-Wvisibility]

c
  •  3
  • criw  · 技术社区  · 6 年前

    首先,我在谷歌上搜索了错误并阅读了以下答案:

    问题就在这两个结构之间, prx_data_s 存储通用数据和 prx_ops_s 它定义指向将使用该数据的函数的指针。

    prx_数据.h

    #ifndef PRX_EXAMPLE_DATA_H
    #define PRX_EXAMPLE_DATA_H
    
    #include "prx_ops.h"
    
    struct prx_data_s {
        enum  prx_op_t op;
        char *keyquery;
    };
    
    char *get_query(struct prx_data_s *dt);
    
    #endif
    

    prx_数据.c

    #include "prx_data.h"
    
    char *get_query(struct prx_data_s *dt)
    {
        return dt->keyquery;
    }
    

    prx_ops.h公司

    #ifndef PRX_EXAMPLE_OPS_H
    #define PRX_EXAMPLE_OPS_H
    
    #include "prx_data.h"
    
    enum prx_op_t {
        PRX_EXAMPLE_OP = 2
    };
    
    struct prx_ops_s {
        int (*dec) (struct prx_data_s *);
    };
    
    #endif
    

    我试图用以下方法编译上面示例中的对象:

    clang -c prx_data.c -o prx_data.o -std=c11 -g -Wall
    

    这是输出错误:

    In file included from prx_data.c:1:
    In file included from ./prx_data.h:4:
    ./prx_ops.h:11:24: warning: declaration of 'struct prx_data_s' will not be visible outside of this function [-Wvisibility]
    int (*dec) (struct prx_data_s *);
                       ^
    

    欢迎所有帮助,谢谢:)

    2 回复  |  直到 6 年前
        1
  •  5
  •   Gerhardh    6 年前

    头部中的循环依赖项有问题:

    prx_data.h:
    
    #include "prx_ops.h" <<< Here we do not yet see the struct definition
    
        prx_ops.h:
    
        #include "prx_data.h"  <<<< Nothing will be included due to inclusion guards.
    
        struct prx_ops_s {
           int (*dec) (struct prx_data_s *);  <<<< Here a new struct type is declared.
        };
    
    later back in prx_data.h:
    
    struct prx_data_s {
      enum  prx_op_t op;
      char *keyquery;
    };
    
        2
  •  3
  •   Yanis.F    6 年前

    阅读时 prx_ops.h prx_data.h 因为编译器正在读取 从开始的include开始 prx_数据.h . 因此,您必须转发声明。

    尝试添加

    struct prx_data_s;
    

    在prx_ops.h开始时`