pkg-config编译安装时提示需要glib库的支持?

操作系统:mac os M4
编译pkg-config时提示需要glib,在pkg-config的源文件中找到了glib直接编译安装,configure可以通过,但是在make时有如下的报错:

gatomic.c:392:10: error: incompatible integer to pointer conversion passing 'gssize' (aka 'long') to parameter of type 'gpointer' (aka 'void *') [-Wint-conversion]
  392 |   return g_atomic_pointer_add ((volatile gpointer *) atomic, val);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./gatomic.h:170:46: note: expanded from macro 'g_atomic_pointer_add'
  170 |     (gssize) __sync_fetch_and_add ((atomic), (val));                         \
      |                                              ^~~~~
gatomic.c:416:10: error: incompatible integer to pointer conversion passing 'gsize' (aka 'unsigned long') to parameter of type 'gpointer' (aka 'void *') [-Wint-conversion]
  416 |   return g_atomic_pointer_and ((volatile gpointer *) atomic, val);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./gatomic.h:177:45: note: expanded from macro 'g_atomic_pointer_and'
  177 |     (gsize) __sync_fetch_and_and ((atomic), (val));                          \
      |                                             ^~~~~
gatomic.c:440:10: error: incompatible integer to pointer conversion passing 'gsize' (aka 'unsigned long') to parameter of type 'gpointer' (aka 'void *') [-Wint-conversion]
  440 |   return g_atomic_pointer_or ((volatile gpointer *) atomic, val);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./gatomic.h:184:44: note: expanded from macro 'g_atomic_pointer_or'
  184 |     (gsize) __sync_fetch_and_or ((atomic), (val));                           \
      |                                            ^~~~~
gatomic.c:464:10: error: incompatible integer to pointer conversion passing 'gsize' (aka 'unsigned long') to parameter of type 'gpointer' (aka 'void *') [-Wint-conversion]
  464 |   return g_atomic_pointer_xor ((volatile gpointer *) atomic, val);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./gatomic.h:191:45: note: expanded from macro 'g_atomic_pointer_xor'
  191 |     (gsize) __sync_fetch_and_xor ((atomic), (val));                          \
      |                                             ^~~~~
4 errors generated.
make[4]: *** [libglib_2_0_la-gatomic.lo] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

请问是哪里出现了问题?

阅读 1.2k
avatarAI BotBETA

可能原因及解决方案:

这个错误通常是由于 GLib 的原子操作宏与 ARM64 架构(M4 芯片)的兼容性问题导致的。以下是关键原因和修复方法:


1. GLib 版本过旧

如果使用的 GLib 版本较旧(< 2.67.0),可能缺少对 ARM64 架构的原子操作兼容性补丁。

解决方案:

  • 下载 GLib 2.70.0 或更新版本

    # 从官方仓库下载最新版
    git clone https://gitlab.gnome.org/GNOME/glib.git
    cd glib && git checkout 2.76.0  # 使用稳定版本

2. 缺少编译器标志

某些 GLib 版本需要显式禁用严格类型转换检查。

修复步骤:

  1. 在编译 GLib 前设置 CFLAGS:

    export CFLAGS="-Wno-error=int-conversion"
  2. 重新配置并编译:

    ./autogen.sh --prefix=/usr/local  # 如果使用默认路径
    make clean && make

3. 通过 Homebrew 安装(推荐)

手动编译 GLib 容易遇到依赖问题,建议使用 macOS 包管理器:

# 安装 Homebrew(如果未安装)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# 安装 GLib
brew install glib

# 确保 pkg-config 能找到 GLib
export PKG_CONFIG_PATH="/usr/local/opt/glib/lib/pkgconfig:$PKG_CONFIG_PATH"

4. 验证依赖库

确保 libffi 等依赖库已正确安装:

brew install libffi

总结:优先通过 Homebrew 安装 GLib,或使用最新 GLib 源码 + 禁用类型转换错误。若问题仍然存在,检查 Xcode 命令行工具是否更新到最新版本(xcode-select --install)。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题