react-native在mac的m2芯片下,pod install安装glog的时候报错

一,报错内容

复制代码
Installing glog (0.3.5)
[!] /bin/bash -c 
set -e
#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# pod 'Flipper-Glog', :podspec => 'https://raw.githubusercontent.com/facebook/flipper/main/pkg/specs/Flipper-Glog.podspec'
set -e

PLATFORM_NAME="${PLATFORM_NAME:-iphoneos}"
CURRENT_ARCH="${CURRENT_ARCH}"
# wget -O config.guess 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'
# wget -O config.sub 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'

if [ -z "$CURRENT_ARCH" ] || [ "$CURRENT_ARCH" == "undefined_arch" ]; then
    # Xcode 10 beta sets CURRENT_ARCH to "undefined_arch", this leads to incorrect linker arg.
    # it's better to rely on platform name as fallback because architecture differs between simulator and device

    if [[ "$PLATFORM_NAME" == *"simulator"* ]]; then
        CURRENT_ARCH="x86_64"
    else
        CURRENT_ARCH="armv7"
    fi
fi

export CC="$(xcrun -find -sdk $PLATFORM_NAME cc) -arch $CURRENT_ARCH -isysroot $(xcrun -sdk $PLATFORM_NAME --show-sdk-path)"
export CXX="$CC"

# Remove automake symlink if it exists
if [ -h "test-driver" ]; then
    rm test-driver
fi

./configure --host arm-apple-darwin

# Fix build for tvOS
cat << EOF >> src/config.h

/* Add in so we have Apple Target Conditionals */
#ifdef __APPLE__
#include <TargetConditionals.h>
#include <Availability.h>
#endif

/* Special configuration for AppleTVOS */
#if TARGET_OS_TV
#undef HAVE_SYSCALL_H
#undef HAVE_SYS_SYSCALL_H
#undef OS_MACOSX
#endif

/* Special configuration for ucontext */
#undef HAVE_UCONTEXT_H
#undef PC_FROM_UCONTEXT
#if defined(__x86_64__)
#define PC_FROM_UCONTEXT uc_mcontext->__ss.__rip
#elif defined(__i386__)
#define PC_FROM_UCONTEXT uc_mcontext->__ss.__eip
#endif
EOF

# Prepare exported header include
EXPORTED_INCLUDE_DIR="exported/glog"
mkdir -p exported/glog
cp -f src/glog/log_severity.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/raw_logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/stl_logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/vlog_is_on.h "$EXPORTED_INCLUDE_DIR/"

checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for arm-apple-darwin-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /opt/homebrew/bin/gmkdir -p
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for arm-apple-darwin-gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.4.sdk
checking whether the C compiler works... no
/Users/huangchuanbiao/Library/Caches/CocoaPods/Pods/External/glog/2263bd123499e5b93b5efe24871be317-6431b/missing: Unknown `--is-lightweight' option
Try `/Users/huangchuanbiao/Library/Caches/CocoaPods/Pods/External/glog/2263bd123499e5b93b5efe24871be317-6431b/missing --help' for more information
configure: WARNING: 'missing' script is too old or missing
configure: error: in `/Users/huangchuanbiao/Library/Caches/CocoaPods/Pods/External/glog/2263bd123499e5b93b5efe24871be317-6431b':
configure: error: C compiler cannot create executables
See `config.log' for more details

二,查看原因

查看了config.log文件,存在两个主要的报错,一个是ruby路径获取不到.

执行了如下策略后再次pod install 不再报错ruby路径获取不到.

复制代码
brew install ruby@3.1
echo 'export PATH="/opt/homebrew/opt/ruby@3.1/bin:$PATH"' >> ~/.zshrc
echo 'export LDFLAGS="-L/opt/homebrew/opt/ruby@3.1/lib"' >> ~/.zshrc  # 修复链接器路径
echo 'export CPPFLAGS="-I/opt/homebrew/opt/ruby@3.1/include"' >> ~/.zshrc  # 修复编译器头文件路径
source ~/.zshrc  # 立即生效

三,第二个原因

架构不兼容(armv7 与 SDK 不匹配)

我的电脑是 M2 芯片(arm64 架构),但 glog 编译脚本强制指定了 armv7 架构(旧架构,多用于 iPhone 5 及更早设备)。

你使用的 Xcode SDK(iPhoneOS18.4.sdk)可能已移除对 armv7 架构的支持(苹果近年已淘汰该架构,最新 SDK 通常只支持 arm64),导致链接器找不到 armv7 版本的系统库(如 libSystem.tbd)。

修改编译架构为 arm64

需要调整 glog 的编译脚本,将架构从 armv7 改为 arm64(适配 M2 芯片和最新 SDK),具体操作如下:

在ios目录下的podfile文件增加这个代码的处理,让强制用arm64

复制代码
    installer.pods_project.targets.each do |target|
     if target.name == 'glog'
        target.build_configurations.each do |config|
          # 核心:强制 arm64 架构
          config.build_settings['ARCHS'] = 'arm64'
          config.build_settings['VALID_ARCHS'] = 'arm64'
          # 适配模拟器(M2 模拟器用 arm64,排除 x86_64)
          config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
          # 可选:只编译当前活跃架构(加速编译)
          config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
        end
      end
    end

然后这个ios-configure-glob.sh文件也改一下:

复制代码
if [ -z "$CURRENT_ARCH" ] || [ "$CURRENT_ARCH" == "undefined_arch" ]; then
    # Xcode 10 beta sets CURRENT_ARCH to "undefined_arch", this leads to incorrect linker arg.
    # it's better to rely on platform name as fallback because architecture differs between simulator and device

    if [[ "$PLATFORM_NAME" == *"simulator"* ]]; then
        CURRENT_ARCH="x86_64"
    else
        CURRENT_ARCH="arm64"//这里改成arm64
    fi
fi

然后清除缓存/重启电脑,再pod install就可以了.

相关推荐
2501_915106329 小时前
iOS 26 能耗监测全景,Adaptive Power、新电池视图
android·macos·ios·小程序·uni-app·cocoa·iphone
Python私教13 小时前
5分钟上手 MongoDB:从零安装到第一条数据插入(Windows / macOS / Linux 全平台图解)
windows·mongodb·macos
Damon小智1 天前
玩转CodeX:CodeX安装教程(Windows+Linux+MacOS)
linux·windows·macos·ai·ai编程·codex·gpt-5
小番茄夫斯基1 天前
团队效率神器!Mac 下 Homebrew 从入门到精通
macos
空安小菜鸟2 天前
Mac 重启电脑导致代理失效
macos
sweethhheart4 天前
【typora激活使用】mac操作方式
前端·数据库·macos
库奇噜啦呼4 天前
【iOS】简单的四则运算
macos·ios·cocoa
HoJunjie4 天前
macOS sequoia 15.7.1 源码安装node14,并加入nvm管理教程
macos·node.js
心灵宝贝4 天前
Principal v6.15 中文汉化版安装教程|Mac .dmg 文件安装步骤详解
macos
你好龙卷风!!!4 天前
mac | Windows 本地部署 Seata1.7.0,Nacos 作为配置中心、注册中心,MySQL 存储信息
windows·mysql·macos