xcode Swift:Apple Mach-O 链接器错误(对于架构 x86_64 文件太小)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30497275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:12:40  来源:igfitidea点击:

Swift: Apple Mach-O Linker Error (file too small for architecture x86_64)

iosxcodeswift

提问by Allister Bah

I'm creating a weather app which gets information from a web site. Everything was fine the last time I was coding (last night), I was able to compile and run the simulator with no errors. Just today when I launch the same project, without changing anything, I got a "Apple Mach-O Linker Error". Could you all help with this please?

我正在创建一个从网站获取信息的天气应用程序。我上次编码时(昨晚)一切正常,我能够编译和运行模拟器而没有错误。就在今天,当我启动同一个项目时,没有做任何更改,我收到了“Apple Mach-O 链接器错误”。请大家帮帮忙好吗?

Here's the details of the error:

这是错误的详细信息:

Ld /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator/Haze\ Meter.app/Haze\ Meter normal x86_64
    cd "/Users/Allister/Documents/XCODE/Haze Meter"
    export IPHONEOS_DEPLOYMENT_TARGET=8.3
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk -L/Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator -F/Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator -filelist /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze\ Meter.build/Debug-iphonesimulator/Haze\ Meter.build/Objects-normal/x86_64/Haze\ Meter.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze\ Meter.build/Debug-iphonesimulator/Haze\ Meter.build/Objects-normal/x86_64/Haze_Meter.swiftmodule -mios-simulator-version-min=8.3 -Xlinker -dependency_info -Xlinker /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze\ Meter.build/Debug-iphonesimulator/Haze\ Meter.build/Objects-normal/x86_64/Haze\ Meter_dependency_info.dat -o /Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Products/Debug-iphonesimulator/Haze\ Meter.app/Haze\ Meter

and at the bottom:

在底部:

ld: file too small (length=0) file '/Users/Allister/Library/Developer/Xcode/DerivedData/Haze_Meter-dkjjcmjehyitmcbhkcbujnsrhwpu/Build/Intermediates/Haze Meter.build/Debug-iphonesimulator/Haze Meter.build/Objects-normal/x86_64/ViewController.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've checked other "Apple Mach-O Linker Error" on StackOverflow but they seem to be having a different "ld" with mine, albeit the same "clang".

我已经检查过 StackOverflow 上的其他“Apple Mach-O 链接器错误”,但它们似乎与我的“ld”不同,尽管是相同的“clang”。

回答by Dharmesh Kheni

Try a full rebuild / clean. It's possible that the a previous build has been abnormally aborted, leaving the ViewController.ofile corrupted or zero-size.

尝试完全重建/清理。之前的构建可能已异常中止,导致ViewController.o文件损坏或大小为零。

To clean: In Xcode "Product" menu, select "Clean" (shortcut: Cmd+Shift+K)

清理:在Xcode“产品”菜单中,选择“清理”(快捷键:Cmd+Shift+K)

To rebuild: In Xcode "Product" menu, select "Build" (shortcut: Cmd+B)

重建:在Xcode“产品”菜单中,选择“构建”(快捷键:Cmd+B)

If it doesn't work: In Xcode "Product" menu, hold down Option key, and select "Clean Build Folder"

如果它不起作用:在Xcode“产品”菜单中,按住Option键,然后选择“清理构建文件夹”

reference from HERE.

这里参考。

回答by colinta

You don't (usually) have to clean, just open the file it mentions and resave it so that xcode thinks it changed. Then you can just do an incremental build (much faster).

您(通常)不必清理,只需打开它提到的文件并重新保存它,以便 xcode 认为它已更改。然后你可以做一个增量构建(更快)。

回答by Carter Cobb

I had the same problem. It turned out to be that one of my frameworks I added externally could not be found. To fix it I removed the reference to it, re downloaded it, then re added it to my project.

我有同样的问题。原来是我在外部添加的其中一个框架找不到。为了修复它,我删除了对它的引用,重新下载它,然后将它重新添加到我的项目中。

回答by Nikhil Manapure

For me it was because of a empty UINavigationControllerstranded in storyboard.

对我来说,这是因为UINavigationController故事板中的空搁浅。

Hope this helps the needy ones.

希望这能帮助有需要的人。

回答by joshia jiang

in my case.i get this error in a framework which is accessed by cocoapods. i fix this error by run cmd 'pod cache clean' and then clean and rebuild project.

就我而言,我在可可豆访问的框架中收到此错误。我通过运行 cmd 'pod cache clean' 来修复这个错误,然后清理并重建项目。

回答by Jakub Sowa

I had the same issue with AppCode. Invalidate Caches / restart didn't help. Fixed issue by manually deleting Library/Caches/AppCodeXXXX/DerivedDatafolder.

我在 AppCode 上遇到了同样的问题。使缓存无效/重新启动没有帮助。通过手动删除Library/Caches/AppCodeXXXX/DerivedData文件夹修复了问题。