新项目把libevent-2.1.11-stable移植到mt7620的Openwrt上,移植完编译的时候遇到一个报错
In file included from /usr/local/include/event.h:68:0,
from /home/project/base.cpp:26:
/usr/local/include/event2/event_struct.h:166:30: error: macro "LIST_HEAD" passed 2 arguments, but takes just 1
LIST_HEAD (event_dlist, event);
^
/usr/local/include/event2/event_struct.h:166:1: error: ‘LIST_HEAD’ does not name a type
LIST_HEAD (event_dlist, event);
搜了下有个哈皮的解决办法竟然是把166行的LIST_HEAD (event_dlist, event);改为 #define LIST_HEAD (event_dlist, event);
性质都不一样了,明显不靠谱。
搜了下头文件 ,LIST_HEAD是在event_struct.h 99行定义的,
97 #ifndef LIST_HEAD
98 #define EVENT_DEFINED_LISTHEAD_
99 #define LIST_HEAD(name, type)
在Openwrt的交叉编译工具链里的list.h找到了同名的宏。
#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
感觉有可能就是冲突了。把libevent里相关的头文件都搜了下,把 所有用到LIST_HEAD的全改成了LIST_HEAD_LIBEVENT。
问题解决。
存在问题:
搜了下文件,发现LIST_HEAD这个宏在交叉编译成库前也有event-internal.h以及bufferevent-internal.h里也有用到。不过考虑到编译的时候第一步预处理就是替换宏,理论上来说不影响。问题不大。