C编译器无法创建可执行文件(安装Cocoapods)

19

在安装RNPermissions及其依赖项时,我遇到了一个错误。似乎是我的编译器或正在安装的软件包出了问题。

错误信息:

checking whether the C compiler works... no
/Users/si/Library/Caches/CocoaPods/Pods/Release/glog/0.3.4-1de0b/missing: Unknown `--is-lightweight' option
Try `/Users/si/Library/Caches/CocoaPods/Pods/Release/glog/0.3.4-1de0b/missing --help' for more information
configure: WARNING: 'missing' script is too old or missing
configure: error: in `/Users/si/Library/Caches/CocoaPods/Pods/Release/glog/0.3.4-1de0b':
configure: error: C compiler cannot create executables
See `config.log' for more details

全部输出:

$ pod install
Analyzing dependencies
Fetching podspec for `Folly` from `../node_modules/react-native/third-party-podspecs/Folly.podspec`
Fetching podspec for `Permission-Camera` from `../node_modules/react-native-permissions/ios/Camera.podspec`
Fetching podspec for `Permission-LocationAlways` from `../node_modules/react-native-permissions/ios/LocationAlways.podspec`
Fetching podspec for `Permission-LocationWhenInUse` from `../node_modules/react-native-permissions/ios/LocationWhenInUse.podspec`
Fetching podspec for `RNPermissions` from `../node_modules/react-native-permissions`
Fetching podspec for `React` from `../node_modules/react-native/`
Fetching podspec for `yoga` from `../node_modules/react-native/ReactCommon/yoga`
Downloading dependencies
Installing DoubleConversion (1.1.5)
Installing Folly (2018.10.22.00)
Using RNPermissions (2.0.3)
Using React (0.59.10)
Installing boost-for-react-native (1.63.0)
Installing glog (0.3.4)
[!] /bin/bash -c 
set -e
#!/bin/bash
set -e

PLATFORM_NAME="${PLATFORM_NAME:-iphoneos}"
CURRENT_ARCH="${CURRENT_ARCH:-armv7}"

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

checking for a BSD-compatible install... /usr/bin/install -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... ./install-sh -c -d
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 undefined_arch -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk
checking whether the C compiler works... no
/Users/si/Library/Caches/CocoaPods/Pods/Release/glog/0.3.4-1de0b/missing: Unknown `--is-lightweight' option
Try `/Users/si/Library/Caches/CocoaPods/Pods/Release/glog/0.3.4-1de0b/missing --help' for more information
configure: WARNING: 'missing' script is too old or missing
configure: error: in `/Users/si/Library/Caches/CocoaPods/Pods/Release/glog/0.3.4-1de0b':
configure: error: C compiler cannot create executables
See `config.log' for more details

嗨,Peter G,你有什么解决这个问题的方案吗? - Anhdevit
8个回答

49

打开 Xcode

  1. 选择 Xcode 转到 偏好设置...

选择 **Xcode** 转到 **偏好设置...**

  1. 选择 位置 并设置 命令行工具

选择 **位置** 并设置 **命令行工具**


1
我解决了我的问题! - Don Diego

17
对我来说,运行sudo xcode-select --reset解决了这个问题。
此外,你可能需要先运行brew install gccbrew upgrade gcc

1
我认为GCC与此无关。重置Xcode应该可以解决它。 - Faizan Noor
Xcode 默认使用 GCC 还是单独的编译器? - Vincent Buscarello
[$ brew install gcc] 对我来说解决了问题 - undefined

6

在XCode首选项中设置XCODE CLI,然后再次运行pod install。

Xcode -> 首选项 -> 位置 -> 命令行工具


5
一个导致我遇到这个错误的边缘情况是 Xcode应用程序路径中有空格
在我的情况下,我不得不将/Applications/Xcode\ 14.2.app重命名为/Applications/Xcode14.2.app,并且当然要使用sudo xcode-select -s /Applications/Xcode14.2.app来更新Xcode的位置。

4

我遇到了同样的问题,稍微有点不同的输出。通过接受Xcode许可证来解决。

sudo xcodebuild -license accept

哇塞,这个方法居然管用!我真的已经试了好几个星期了,好几个星期啊。非常感谢你! - Filippo Fonseca

2

我曾经遇到过类似的情况。可执行文件的名称不是“Xcode.app”,而是“Xcode 13.app”,这意味着编译过程无法找到它。将名称从“Xcode 13”改为“Xcode”解决了我的问题。 - Antonio Jaime

1

我尝试了很多建议,最终在这里找到了一个不完美的解决方法:https://github.com/facebook/react-native/issues/32291#issuecomment-929965479

我执行了which gcc命令,并在上面提到的脚本的export CC行使用了该路径。

当然,在node_modules中直接编辑不是最好的方法,因为任何更新都会将其覆盖,但至少它允许pod install完成。


目前你的回答不够清晰。请编辑并添加更多细节,以帮助其他人理解它如何回答所提出的问题。你可以在帮助中心找到有关如何撰写好答案的更多信息。 - Community
这对我有用。我只是在我的项目根目录下执行了 brew install gcc,然后执行了 sed -i 's|CC=.*|CC="gcc"|' node_modules/react-native/scripts/ios-configure-glog.sh。请注意,我使用的是 GNU sed 4.8 版本。 - undefined

0

升级 GCC 后问题消失了。

brew update
brew upgrade
brew info gcc
brew install gcc
brew cleanup

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接