You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译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相关文件」是必要操作,具体修改步骤如下:

  1. 在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
  1. 在项目根目录的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 $< $@
  1. 修改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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 03:45:01