Libtool:找不到文件:-lPods-RCTMapboxGL

Libtool: can't locate file for: -lPods-RCTMapboxGL

我的 React Native 项目的链接阶段出现问题。库 libRCTMapboxGL.a 导致了这个问题。

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-RCTMapboxGL

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods-RCTMapboxGL is not an object file (not allowed in a library)

由于 -lPods-RCTMapboxGL 的错误,文件 libRCTMapboxGL.a 未在 /Users/user/Developer/RNProject/ios/build/Build/Products/Debug-iphonesimulator/ 中创建。但是,文件似乎存在:

/Users/user/Developer/RNProject/node_modules/react-native-mapbox-gl/ios/Pods/Target Support Files/Pods-RCTMapboxGL/Pods-RCTMapboxGL.debug.xcconfig

/Users/user/Developer/RNProject/node_modules/react-native-mapbox-gl/ios/Pods/Target Support Files/Pods-RCTMapboxGL/Pods-RCTMapboxGL.release.xcconfig

Pods-RCTMapboxGL is not an object file 在错误信息中看起来很奇怪,文件的内容是:

 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public"
OTHER_LDFLAGS = $(inherited) -ObjC
PODS_BUILD_DIR = $BUILD_DIR
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}/Pods

设置是根据这个tutorial完成的。首先使用 CocoaPods 然后我手动验证是否所有设置和文件都已到位。

完整错误日志:

Libtool /Users/user/Developer/RNProject/ios/build/Build/Products/Debug-iphonesimulator/libRCTMapboxGL.a normal x86_64
    cd /Users/user/Developer/RNProject/node_modules/react-native-mapbox-gl/ios
    export IPHONEOS_DEPLOYMENT_TARGET=8.0
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk -L/Users/user/Developer/RNProject/ios/build/Build/Products/Debug-iphonesimulator -L/Users/bobby/Downloads/mapbox-gl-ios-0.2.17 -L/Users/user/Developer/RNProject/node_modules/react-native-mapbox-gl/ios/RCTMapboxGL -filelist /Users/user/Developer/RNProject/ios/build/Build/Intermediates/RCTMapboxGL.build/Debug-iphonesimulator/RCTMapboxGL.build/Objects-normal/x86_64/RCTMapboxGL.LinkFileList -lPods-RCTMapboxGL -o /Users/user/Developer/RNProject/ios/build/Build/Products/Debug-iphonesimulator/libRCTMapboxGL.a

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-RCTMapboxGL
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -lPods-RCTMapboxGL is not an object file (not allowed in a library)

问题是我在 MapboxGL 目录中使用了 pod init,它创建了额外的文件。删除生成的文件解决了问题。