简体   繁体   English

结构数组-数组的元素类型不完整(在C中)

[英]Array of structs - Array has incomplete element type (in C)

This seems like an easy problem to fix, but i'm doing something wrong. 这似乎是一个容易解决的问题,但是我做错了事。 I've been through all the similar threads and didn't find anything that solved my problem, so any help would be appreciated! 我经历了所有类似的话题,没有找到能解决我问题的任何东西,因此,我们将不胜感激!

Basically: C program, and i'm trying to create an array of bufferevents. 基本上:C程序,并且我正在尝试创建一个bufferevents数组。

#include <event2/listener.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>

extern struct bufferevent bev[8];

//Then, my accept functions -- well, one of them...
static void accept1(struct evconnlistener *listener,
    evutil_socket_t fd, struct sockaddr *address, int socklen,
    void *ctx) {
    /* A new connection was received on this port */
    struct event_base *base = evconnlistener_get_base(listener);
    bev[0] = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);

    /* Callback for when (*bufevent, data READ, data WRITTEN, event OCCURRED, *void) */
    bufferevent_setcb(bev[0], read1, NULL, echo_event_cb, NULL);
} 

When i attempt to compile (WITH -levent, i might add) i get this error: 当我尝试编译(带有-levent时,我可能会添加)时,出现此错误:

src/mix/mix1.c:57:34: error: array type has incomplete element type

Any ideas? 有任何想法吗? :( :(

Note: I am defining the bufferevents outside of main to make them accessible everywhere in my code without passing them. 注意:我正在main之外定义bufferevent,以使它们在我的代码中的任何位置都可以访问而无需传递它们。 I have other #define's in the area, so i'm sure it's something to do with the way i'm building them?? 我在该地区还有其他#define,所以我确定这与我建立它们的方式有关?

struct bufferevent is only declared as an incomplete type in libevent's public headers; struct bufferevent仅在libevent的公共标头中声明为不完整类型; its contents are hidden to users of the public API. 它的内容对公共API的用户隐藏。 All the libevent functions that operate on bufferevents take a pointer to a bufferevent, so what you want here is 所有对bufferevents进行操作的libevent函数都使用一个指向 bufferevent的指针 ,因此,您想要的是

struct bufferevent *bev[8];

Note further that you do NOT want to put extern on that declaration or you'll get an undefined symbol error at link time. 还要注意,您不想在该声明上加上extern ,否则在链接时会收到未定义的符号错误。 If it is only ever referred to in that file , you should use static instead. 如果仅在该文件中引用过 ,则应该使用static Otherwise there should be a declaration with extern in one of your application's header files in addition to the extern -less declaration in the file you showed. 否则,除了显示的文件extern -less声明 ,您的应用程序文件还应有一个带有extern声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM