编译Wayland相关代码时出现undefined reference to ‘xdg_popup_interface’链接错误
问题解决说明
wayland-protocols 包本身仅提供协议的XML定义文件,不提供编译参数和预编译链接库,因此你在autotools输出中看不到WAYLAND_PROTOCOLS_CFLAGS和WAYLAND_PROTOCOLS_LIBS的具体值属于正常情况。
你遇到的undefined reference to ‘xdg_popup_interface’报错,本质是没有将xdg-shell协议对应的生成代码加入编译链,你更新中提到的「自行使用wayland-scanner生成xdg-shell相关文件」是必要操作,具体修改步骤如下:
- 在
configure.ac.in中添加wayland-scanner工具的检测逻辑:
AC_CHECK_PROG([WAYLAND_SCANNER], [wayland-scanner], [wayland-scanner]) if test -z "$WAYLAND_SCANNER"; then AC_MSG_ERROR([Missing required build tool wayland-scanner]) fi
- 在项目根目录的
Makefile.am中添加xdg-shell协议代码的生成规则,你用到的是不稳定版xdg-shell v1,参考配置如下:
noinst_LIBRARIES = libxdg-shell-unstable-v1.a libxdg_shell_unstable_v1_a_SOURCES = \ xdg-shell-unstable-v1-protocol.c \ xdg-shell-unstable-v1-server-protocol.h # 从wayland-protocols提供的XML生成C代码 xdg-shell-unstable-v1-protocol.c: $(ac_wayland_protocols_pkgdatadir)/unstable/xdg-shell/xdg-shell-unstable-v1.xml $(WAYLAND_SCANNER) public-code $< $@ # 生成服务端用头文件 xdg-shell-unstable-v1-server-protocol.h: $(ac_wayland_protocols_pkgdatadir)/unstable/xdg-shell/xdg-shell-unstable-v1.xml $(WAYLAND_SCANNER) server-header $< $@
- 修改
src/Makefile.am,将生成的协议代码加入你的项目编译链:
# 引入生成的协议头文件 xfway_CFLAGS += -I$(top_builddir) # 链接生成的协议静态库 xfway_LDADD += $(top_builddir)/libxdg-shell-unstable-v1.a
另外你仓库内的wlr-layer-shell协议XML,也需要用同样的方式生成对应C代码和头文件加入编译,仅存放XML文件无法被编译系统识别使用。
内容的提问来源于stack exchange,提问作者adlo
相关产品推荐
相关产品推荐

