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

macOS Ventura编译ESP目标QEMU出现'glib.h'文件未找到错误

解决macOS编译ESP目标QEMU时找不到glib.h的问题

问题描述

使用ninja -C build编译ESP目标的QEMU时,出现'glib.h' file not found错误,尽管编译命令中已经包含了glib的include路径,但依然报错。具体错误日志如下:

> ninja -C build
         ^~~~~~~~
1 error generated.
[4/1471] Compiling C object tests/plugin/libsyscall.dylib.p/syscall.c.o
FAILED: tests/plugin/libsyscall.dylib.p/syscall.c.o
cc -Itests/plugin/libsyscall.dylib.p -Itests/plugin -I../tests/plugin -I../include/qemu -I/usr/local/Cellar/glib/2.74.5/include -I/usr/local/Cellar/glib/2.74.5/include/glib-2.0 -I/usr/local/Cellar/glib/2.74.5/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre2/10.42/include -fcolor-diagnostics -Wall -Winvalid-pch -std=gnu11 -O0 -g -iquote . -iquote /Users/flying_raijin/espressif/qemu -iquote /Users/flying_raijin/espressif/qemu/include -iquote /Users/flying_raijin/espressif/qemu/tcg/aarch64 -fsanitize=undefined -fsanitize=address -DOS_OBJECT_USE_OBJC=0 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-at-end -fstack-protector-strong -MD -MQ tests/plugin/libsyscall.dylib.p/syscall.c.o -MF tests/plugin/libsyscall.dylib.p/syscall.c.o.d -o tests/plugin/libsyscall.dylib.p/syscall.c.o -c ../tests/plugin/syscall.c
../tests/plugin/syscall.c:13:10: fatal error: 'glib.h' file not found
#include <glib.h>
         ^~~~~~~~
1 error generated.
[5/1471] Compiling C object tests/plugin/libmem.dylib.p/mem.c.o
FAILED: tests/plugin/libmem.dylib.p/mem.c.o
cc -Itests/plugin/libmem.dylib.p -Itests/plugin -I../tests/plugin -I../include/qemu -I/usr/local/Cellar/glib/2.74.5/include -I/usr/local/Cellar/glib/2.74.5/include/glib-2.0 -I/usr/local/Cellar/glib/2.74.5/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre2/10.42/include -fcolor-diagnostics -Wall -Winvalid-pch -std=gnu11 -O0 -g -iquote . -iquote /Users/flying_raijin/espressif/qemu -iquote /Users/flying_raijin/espressif/qemu/include -iquote /Users/flying_raijin/espressif/qemu/tcg/aarch64 -fsanitize=undefined -fsanitize=address -DOS_OBJECT_USE_OBJC=0 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-at-end -fstack-protector-strong -MD -MQ tests/plugin/libmem.dylib.p/mem.c.o -MF tests/plugin/libmem.dylib.p/mem.c.o.d -o tests/plugin/libmem.dylib.p/mem.c.o -c ../tests/plugin/mem.c
../tests/plugin/mem.c:13:10: fatal error: 'glib.h' file not found
#include <glib.h>
         ^~~~~~~~

解决方案

注意:这不是PATH变量的问题,PATH用于查找可执行文件,头文件查找依赖编译时的include路径,而QEMU编译依赖pkg-config自动获取glib的配置信息,核心是让pkg-config能正确识别glib的安装路径。

  • 确认glib是否正确安装
    先检查glib的头文件是否存在:

    ls /usr/local/Cellar/glib/2.74.5/include/glib-2.0/glib.h
    

    如果文件不存在,重新安装glib:

    brew reinstall glib
    
  • 设置pkg-config的路径
    执行以下命令让pkg-config找到glib的配置文件(.pc):

    export PKG_CONFIG_PATH="/usr/local/Cellar/glib/2.74.5/lib/pkgconfig:$PKG_CONFIG_PATH"
    

    验证是否生效:

    pkg-config --cflags glib-2.0
    

    正常输出应包含glib的include路径,比如-I/usr/local/Cellar/glib/2.74.5/include/glib-2.0 ...

  • 重新配置QEMU
    之前的configure可能未正确获取glib信息,删除现有build目录后重新配置:

    rm -rf build
    mkdir build && cd build
    # 根据你的ESP目标选择对应的target-list,比如ESP32用xtensa-softmmu
    ../configure --target-list=xtensa-softmmu,xtensa-linux-user
    
  • 重新编译
    再次执行编译命令:

    ninja -C build
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 20:23:10