clang: error: linker command failed with exit code 1 (use -v to see invocation)

Just updated to the latest XCode. Big mistake. Why must Apple ruin my project everytime they update Xcode? I might give up on Swift development if I can't get this fixed easily.


The error I get is: clang: error: linker command failed with exit code 1 (use -v to see invocation)



How should I go about fixing it? Already tried build clean and restarted XCode a bunch.

Replies

That message isn't the error, it's just a message telling you there is an error.


Go to the build log (click the last icon across the top of the navigator pane), expand the transcript with the error, and if necessary click the details icon to see the error message(s) produced by the linker.

Here is the error:


Ld /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/name.app/PlugIns/nameTest.xctest/nameTests normal x86_64

cd /Users/name/Documents/Development/appName/appName

export IPHONEOS_DEPLOYMENT_TARGET=9.1

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/clang -arch x86_64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk -L/Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator -F/Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -filelist /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -mios-simulator-version-min=9.1 -bundle_loader /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/appName.app/appName -Xlinker -object_path_lto -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.swiftmodule -lsqlite3 -framework XCTest -Xlinker -dependency_info -Xlinker /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests_dependency_info.dat -o /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Products/Debug-iphonesimulator/appName.app/PlugIns/appNameTests.xctest/appNameTests

ld: /Users/name/Library/Developer/Xcode/DerivedData/appName-gwipifpkqxuqdbeopzfzxqnhkamn/Build/Intermediates/appName.build/Debug-iphonesimulator/appNameTests.build/Objects-normal/x86_64/appNameTests.o compiled with newer version of Swift language (3.0) than previous files (2.0) for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

So the real error is the 2nd to last line of this:


ld: /Users/…/appNameTests.o compiled with newer version of Swift language (3.0) than previous files (2.0) for architecture x86_64


Swift currently requires all code in an application to be compiled with exactly the same version of the Swift compiler, and all code to use the same language syntax. (That's because the ABI — application binary interface — that controls name mangling and calling conventions is different in these cases.) Your project apparently has some source files that haven't been converted from Swift 2 to Swift 3.


Select the project item in the navigator pane, then go down the list of targets that's displayed. For each one, use Edit -> Convert to check that it has been converted to Swift 3.

What did "preferredStyle: UIAlertControllerStyle.Alert" and "style: UIAlertActionStyle.Default" translate to in Swift 3.0? This is a mess.

In general, enum cases starting with a capital letter changed to a lower-case letter in Swift 3.


Note that when passing a parameter, the compiler can infer the type, so you don't need (for example) to enter the type name. You can have just:


preferredStyle: .alert


I mention this because the easiest way to fix many of the syntax errors resulting from Swift 3 conversion by re-typing and letting autocomplete supply the correct syntax. In the above example, if you type the "." for the style, autocomplete should pop up with a menu of valid styles.


> This is a mess.


Yes, Swift 3 syntax conversion doesn't actually do all of the necessary conversions. In some cases, a different conversion error prevents it from changing something it otherwise should have (such as the capitalization of enum cases). In other cases, it just fails to convert some things.


But you should persevere. Swift 3 embraces the pain of conversion so that future Swifts don't have to. At least, that's the theory.

Thanks. I have a few more I need your help to translate to Swift 3.0:


let reference = CKReference(recordID: xxxx.recordID, action: .deleteSelf) //Complains that CKReferenceAction has no member deleteSelf but it will clearly let you select .deleteSelf


dispatch_async(NSDispatchQueue.main) {

} //Whats the deal with this one? Let's me select NSDispatchQueue.main but complains "Use of unresolved identifier 'NSDispatchQueue'"

let reference = CKReference(recordID: xxxx.recordID, action: .deleteSelf)


My guess is that this is a secondary error, and what's really wrong is something to do with your recordID. Is that possible?


dispatch_async(NSDispatchQueue.main) { … }


GCD has been "wrapped" in a better API for Swift 3. Instead of the above, use


DispatchQueue.main.async { … }


For more information about the other classes and declarations, see:


developer.apple.com/reference/dispatch


Note that it's just the APIs that have changed. The functionality is the same underneath.

The compiler doesn't seem to recognize DispatchQueue.main.async { … } for some reason. What could be causing that?

Did you import Foundation? I can't think of any other reason. What's the exact error message?

It gives me the error "Use of unresolved identifier 'DispatchQueue'". It won't even give me the option to put "import Foundation" at the top of my code. It makes me pick "CoreFoundation" or "AVFoundation"

You don't need "permission" to put "import Foundation" in your source file. Just type it.

Unfortunately, adding "import Foundation" at the top of the files affected did not fix the errors.


I'm still getting the error: Type 'CKReferenceAction' has no member .deleteSelf

For line: let reference = CKReference(recordID: record.recordID, action: .deleteSelf)


Also the error: Use of unresolved identifier 'DispatchQueue'

For line: DispatchQueue.main.async { }


Any additional suggestions for how to fix this?

My guess is that this particular source file is still being compiled as Swift 2 instead of Swift 3. (After all, you started this thread with an error that told you there were mixed Swift versions in your link.)


Sorry it's frustrating, but there must be something simple-but-obscure wrong.

For the DispatchQueue error.


Comment it out, then underneath begin typing it again and follow the autocomplete.


I just hashed up an empty project using Foundation and it had no issues with me including DispatchQueue.main.async.


As for your other issue try changing it to

let reference = CKReference(recordID: record.recordID, action: CKReferenceAction.DeleteSelf)

Thank you for your suggestion on the reference issue. That cleared up that issue.


But for DispatchQueue when I start typing, XCode does not give me an option to select DispatchQueue. Only "dispatch_queue_t", "DISPATCH_IO_STOP", etc.