找不到-lDoubleConversion库

35

我尝试在 XCode 上进行构建,但出现了 "ld: library not found for -lDoubleConversion" 错误。我可以使用 react-native run-ios 进行构建,这样是可行的,但是 XCode 无法构建...

ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/DoubleConversion' 所对应的目录 ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/Folly' 所对应的目录 ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/GTMOAuth2' 所对应的目录 ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/GTMSessionFetcher' 所对应的目录 ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/Google-Maps-iOS-Utils' 所对应的目录 ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/GoogleToolboxForMac' 所对应的目录 ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/Protobuf' 所对应的目录 ld: 警告: 找不到选项 '-L/Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/React' 所对应的目录

ld: 警告:未找到选项“-L /Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/glog”的目录。 ld: 警告:未找到选项“-L /Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/leveldb-library”的目录。 ld: 警告:未找到选项“-L /Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/nanopb”的目录。 ld: 警告:未找到选项“-L /Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/react-native-google-maps”的目录。 ld: 警告:未找到选项“-L /Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/react-native-maps”的目录。 ld: 警告:未找到选项“-L /Users/xxxxx/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/yoga”的目录。 ld: 无法找到库-lDoubleConversion。 clang: 错误:链接器命令失败,退出码为1(使用-v查看调用)。


在 M1 芯片上,使用 Rosetta 运行 Xcode 对我来说是可行的: https://dev59.com/i1IG5IYBdhLWcg3wkyCl#71115807 - Waweru Kamau
16个回答

64

对我来说,解决方法就是打开 MyAppName.xcworkspace 而不是 MyAppName.xcodeproj ,然后进行构建。


1
对我来说也是...但为什么? - Sandy
6
可能的原因是您正在使用CocoaPods,而这些pod仅在工作区中包含,因此在从xcodeproj构建时不会被构建。 - Daniel Schlaug
2
对于像我这样刚接触React Native的新手,你可以在[project_name]/ios/路径下找到*.xcworkspace文件 —— 在Xcode中打开它,而不是*.xcodeproj文件(我曾经因为xcworkspace和xcodeproj的区别困惑了半个小时)。 - Dru
这应该被标记为正确答案 @Shun Yamada - Arundale Ramanathan
太酷了!!!非常感谢!!! - Andrey Mashukov
显示剩余3条评论

15

我在升级到RN 0.59后遇到了这个问题。

对我有效的解决方案是删除ios/build文件夹,然后执行以下操作:

cd ios

pod install

当我这样做时,我看到了一个关于错误的提示,并且人们推荐这样做:
pod deintegrate

pod install

我做了这件事,但它仍然报错有关 Folly,所以我删除了 Podfile.lock,因为pods握有与RN 0.59不兼容的旧版本Folly。

注意:我发现一篇帖子说不建议删除整个锁定文件。相反,您应该只删除与Folly相关的行,即与Folly相关的行。我已经删除了锁定文件,但一切都运转良好。

我运行了 pod update ,更新了很多东西,并成功完成。

下次我再次运行 pod install ,它会产生一个漂亮的绿色,安装成功的列表。

然后我又运行了 react-native run-ios ,这是一段时间以来的第一次运行,除了产生红色死机屏幕外,一切正常。

所以我从iOS模拟器设备中删除了我的应用程序,然后运行:

rm -rf node_modules

npm install

killall -9 node
killall -9 node 只是用来关闭 Metro Bundler 的命令。这是我最喜欢的清理命令。如果你的机器上正在运行十二个 node.js API,那么可以尝试使用 sudo lsof -i :8081 命令查找 Metro Bundler 的进程 ID 并通过 PID 来杀死该进程。例如,如果你看到 Metro Bundler 进程的 PID 是 27322,则运行 kill -9 27322 来结束它。

然后我在独立的终端中运行了这个命令:

npm start -- --reset-cache

回到 VS Code 集成终端:

react-native run-ios

IT WORKED !!!!!!!!

然后我运行了:

react-native run-android

这样做可以解决问题,但是在模拟器设备上会卡在0%,所以我把APK文件从模拟器中删除,然后再次运行react-native run-android

成功了!!!!!!!!


12
热爱热情 - Sandy
在我添加了另一个包并执行了 npm i 后,它停止工作了。 - Alex Buznik

7

当我在终端上构建项目而非在 Xcode 上构建时,我遇到了这个问题,而且这个问题在我的笔记本和CI上都出现了。

这种情况发生是因为你在构建过程中使用了 app.xcodeproj 而不是 app.xcworkspace

所以,你需要改变调用中的参数,将 -project app.xcodeproj 改为 -workspace app.xcworkspace。请注意,不仅值会发生改变,参数名称也会发生改变。

以下是完整的调用示例。

从:

xcodebuild -sdk iphoneos -configuration yourconfig -project app.xcodeproj -scheme yourscheme build -UseModernBuildSystem=YES CODE_SIGN_STYLE=Automatic

到:

xcodebuild -sdk iphoneos -configuration yourconfig -workspace app.xcworkspace -scheme yourscheme build -UseModernBuildSystem=YES CODE_SIGN_STYLE=Automatic


5

我刚刚将部署目标从10更新到11.4,它可以正常工作了。


5

我尝试了数个小时的其它方法,最终可行的是在我的Podfile文件中设置:

platform :ios, '10.0'

与 Info.plist 中 iOS 部署目标版本 相同,但它们是不同的。

4

经过我三天的努力,我找到了以下解决方案。

  1. 检查是否需要打开 MyAppName.xcworkspace 而不是 MyAppName.xcodeproj
  2. 关闭 Xcode 并尝试进行 Pod deintegrate 然后 Pod Install
  3. 将构建设置从 Legacy 更改为 New build system

对我来说,选项 3 最终解决了问题。


1
"MyAppName.xcworkspace 而不是 MyAppName.xcodeproj":你让我开心极了! - lsmpascal

3
XCode无法找到lDoubleConversion库,您需要将该库添加到Cocoa Pods文件中。您可以按照以下步骤轻松完成此操作:
1.将库文件添加到您的Podfile中。
pod 'DoubleConversion', :podspec => './../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'

2.删除Podfile.lock文件

3.运行pod install命令

4.将DoubleConversion.a添加到xcode的链接框架和库中

5.清理项目并重新构建。

这样应该就可以了。


我在哪里可以找到DoubleConversion.a并添加它? - Vedavyas Bhat
1
不确定 DoubleConversion.a 是什么,但是 DoubleConversion 库在 node_modules/react-native/third-party 中。 - BONEMX

2
在 Podfile 中,使用 platform :ios,'10.0' 代替 platform :ios,'11.0'。

2
尝试在真实的iOS设备上检查您的项目是否运行良好,因为在我的情况下,此错误仅适用于模拟器构建,因为我使用的是M1 Pro芯片的Mac。
要解决此问题,您需要检查“Build Settings”->“Targets”->“Architectures”->“Excluded Architectures”,并验证arm64未从项目中排除。如果它被排除了,您应该将其删除以在M1芯片的模拟器上运行。 enter image description here

2
以下步骤对我有用:

以下是最初的回答:

  1. Remove use_frameworks! from ios/Podfile.

    target 'AwesomeProject' do
        # use_frameworks!
        ...
    end
    
  2. Add DoubleConversion pod in ios/Podfile

    target 'AwesomeProject' do
        # use_frameworks!
        ...
        pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
    end
    
  3. Clear pods.

    pod deintegrate
    
    pod rm Podfile.lock
    
  4. Reinstall pods

    pod install --repo-update --verbose
    
  5. Open AwesomeProject.xcworkspace and run your app.

希望这能帮助到某些人 :),最初的回答如下:

@RocBoronat 当然可以,它意味着删除该文件。由于它只是一个文件而不是文件夹,所以选项“-r”是不必要的;根据文件权限和您在系统中的用户权限,您可能需要使用“-f”。 - Ashwin
哦,我明白了。但是你写的是 pod rm Podfile.lock。也许有人会因此迷失方向。 - Roc Boronat

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