Apple Mach-O Linker & Ditto Error - Xcode 8

2020-02-03 07:35发布

问题:

I have just updated my Xcode to Xcode 8 and am now trying to convert my project's code to Swift 2.3. I was able to build a couple times using Xcode 8 without any errors. Now, the following errors came up:

Error #1: Apple Mach-O Linker Error: Linker command failed with exit code 1

ld: file not found: /Users/Linus/Library/Developer/Xcode/DerivedData/MyApp-asdjeshhsetnfxbegcsbcipdreneewgr/Build/Intermediates/MyApp.build/Debug-iphonesimulator/MyApp.build/Objects-normal/x86_64/DownloadsViewController.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't even know what a .o file is. The swift file of DownloadsViewController is there, though.

Error #2: Ditto Error: Command /usr/cin/ditto failed with exit code 1

ditto: can't get real path for source '/Users/Linus/Library/Developer/Xcode/DerivedData/MyApp-asdjeshhsetnfxbbciegrfdpdreneewgr/Build/Intermediates/MyApp.build/Debug-iphonesimulator/MyApp.build/Objects-normal/x86_64/MyApp-Swift.h'
Command /usr/bin/ditto failed with exit code 1

The ditto error occurs 3 times: for MyApp.swiftdoc, MyApp.swiftmodule, and MyApp-Swift.h.

Thanks in advance!

回答1:

  1. Quit Xcode
  2. Restart the System
  3. Select Xcode -> Preferences.
    This will open a pop-up window. Select 'Locations'. In Locations, you will see 'Derived Data'. Click on the arrow icon right next to the path.
    This will open a folder containing 'Derived Data', delete it.
  4. Clean the Product and Run


回答2:

Make sure you open the project from the .xcworkspace file instead of the .xcodeproj



回答3:

step 1 = clicking on the project in the navigation menu

step 2 = select the project

step 3 = build settings

step 4 = search enable bitcode if bitcode is yes than change to No



回答4:

None of the previous answer have solve my problem. I think it come from changes in the cocoapods podFile, from using frameworks to not using them

Frameworks was still remind in Target>General Properties>Linked Frameworks. I removed them I also remove the -framework and corresponding frameworks from other linker flags (saving inherited and objC flags)

Hope that could help



回答5:

This happened to me after I delete my app while it was running.

I solved it cleaning the project.

Product > Clean or Shift + Command + K



回答6:

This is because at some point some project file was not compiled. In my case the AppDelegate.swift was not in the compiler. So I added it manually and it worked.



回答7:

Clean XCode with following cmds and rebuild:

rm -rf ~/Library/Developer/Xcode/DerivedData/
killall Xcode 2> /dev/null
killall Instruments 2> /dev/null
killall 'iOS Simulator' 2> /dev/null
killall Simulator 2> /dev/null
killall 'Simulator (Watch)' 2> /dev/null
killall ibtoold 2> /dev/null
killall simctl 2> /dev/null
# There may be others
# Kill the service itself
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService
rm -rf ~/Library/*/CoreSimulator


回答8:

For my react native app, I deleted a folder of a test project inProject Navigator and Targets. It solved my problem.



回答9:

Don't wory ,just go to your project targat and then build setting and search enable bitcode change it to YES to NO.



回答10:

Turning Bitcode to "No" solved this issue. This is found in the Build Settings.



回答11:

I had the same problem when I changed Xcode from a previous version 7 to the new XCode 8. In the new Xcode (8.3.3 now) there are more settings in the compiler.

When you update the project settings into new Xcode (using Editor->Validate Settings), these new settings are applied and set to the default value YES. After this update I had the linker error!

In my project I compared the previous version of the file .pbxproj with the new one (after Settings validation) using Beyond compare (or similar).

In this way I can saw the new settings added in the new version of Xcode and I set the new Settings value to NO. After this update all was OK and the linker error disappear.



回答12:

If you're importing a framework through Build Phases, try to put it inside the folder of your project and add it into Link Binary with libraries. Actually, I've already experienced that problem before, I am very frustrated with that error until I knew that I have to put the .framework inside the folder of my project. Hope will help



回答13:

On top of cleaning derived data and the project and restarting xcode, I've found that re converting your project to current swift syntax and re installing pods if you have them also helps.

To re convert your project you will need to set swift_version build setting back to yes so that your target appears in the conversion list.



回答14:

The issue I found with XCode 8.2.1 (Version 8C1002) after I converted the project to Current Swift Syntax (Swift 3). I just needed to rebuild it after cleaning, and the errors disappeared.



回答15:

If the procedure of cleaning and the disabling of bitcode does not work, then it's possible that the reason for the errors simply is a more complex syntax error in your code.



回答16:

I got the same problem because I had defined a class (using @interface), but did not provide an implementation (using @implementation) for it. It was a simple class so even an empty implementation resolved it.



回答17:

Also just check if you are importing a "*.m" implementation file in any of your classes, that can cause the same issue.

Removing the import statement can fix the issue



回答18:

For me it was a problem with react native haptic. I think it was because of a change in CocoaPods but also because of changing up file locations. I just removed it and re installed it. Hope this helps someone.

UPDATE

The build succeeded by when running it it would just crash. To solve this I used File > Add Files to Project for the GoogleService-Info.plist and it worked.



回答19:

Please make sure you have following changes in Workspace setting in your xcode:

Please go to your workspace setting and make the following changes:

Workspace Setting: Build System: Legacy Build System

Per -User Workspace DerivedData: Workspace relative location Build System Use User Setting

Hope it helps:



回答20:

Follow the below steps:

step1: Go to Build Phase Tab then only expand Link Binary with Library

step2: Then Go to General Tab then Expand Linked Framework & Library (because Yourprojectname.framework is disable)