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

编译libpipewire程序失败:pw_registry_events类型未定义求助

解决Pipewire编译时pw_registry_events类型不完整的问题

问题原因

你遇到的错误源于两个核心问题:

  • 缺少pw_registry_events结构定义对应的头文件
  • 使用了过时的Pipewire 0.2版本库,当前系统通常默认安装的是主流稳定版Pipewire 0.3

修复步骤

1. 补充必要的头文件

pw_registry_events的定义不在<pipewire/pipewire.h>中,需要显式包含注册表头文件。修改代码的include部分:

#include <pipewire/pipewire.h>
#include <pipewire/registry.h>  // 新增这行
#include <stdio.h>              // 新增,确保printf函数可用

2. 使用正确的编译命令

放弃手动指定-lpipewire-0.2,改用pkg-config自动适配系统中的Pipewire版本(通常是0.3),命令如下:

gcc main.c -o test1 $(pkg-config --cflags --libs pipewire-0.3)

若你的系统确实仅安装了0.2版本,可将命令中的pipewire-0.3替换为pipewire-0.2,但建议优先升级到0.3版本(0.2已停止维护)。

3. 验证API版本匹配

代码中的PW_VERSION_REGISTRY_EVENTS宏会自动匹配系统Pipewire版本,0.3版本该宏值为3,0.2版本为2,pkg-config会自动处理头文件路径,无需手动修改宏定义。

完整修正后的代码

#include <pipewire/pipewire.h>
#include <pipewire/registry.h>
#include <stdio.h>

static void registry_event_global(void *data, uint32_t id,
            uint32_t permissions, const char *type, uint32_t version,
            const struct spa_dict *props)
{
    printf("object: id:%u type:%s/%d\n", id, type, version);
}

static const struct pw_registry_events registry_events = {
    PW_VERSION_REGISTRY_EVENTS,
    .global = registry_event_global,
};

int main(int argc, char *argv[])
{
    return 0;
}

内容的提问来源于stack exchange,提问作者ibse

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 21:13:11