9

I recently updated XCode to V 11.1, and since updating, for some reason when I run my app in release mode, I'm thrown the following error:

ld: can't link with a main executable file '/Users/me/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Products/Release-iphoneos/myapp.app/myapp' for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have absolutely no clue how to resolve this - and I can't run my app in release mode without it (and yes, I'm using a Distribution profile). Help would be much appreciated. I've browsed a few other answers but none seem to solve this issue.

When I navigate to that file path, 'myapp' is simply an icon with a circle and a slash through it (can't be a good sign). This same thing occurs even after I clean the build folder. When I try to rebuild in release mode, the build fails and throws me the above yet again.

See full error:

Ld /Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Intermediates.noindex/myapp.build/Release-iphoneos/myappTests.build/Objects-normal/armv7/Binary/myappTests normal armv7 (in target 'myappTests' from project 'myapp') cd /Users/admin/Desktop/myapp /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target armv7-apple-ios8.4 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.1.sdk -L/Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Products/Release-iphoneos -F/Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Products/Release-iphoneos -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.1.sdk/Developer/Library/Frameworks -F/Users/admin/Desktop/myapp/Pods/FirebaseAnalytics/Frameworks -F/Users/admin/Desktop/myapp/Pods/GoogleAppMeasurement/Frameworks -F/Users/admin/Desktop/myapp/Pods/GoogleMaps/Base/Frameworks -F/Users/admin/Desktop/myapp/Pods/GoogleMaps/Maps/Frameworks -F/Users/admin/Desktop/myapp/Pods/GooglePlaces/Frameworks -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -filelist /Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Intermediates.noindex/myapp.build/Release-iphoneos/myappTests.build/Objects-normal/armv7/myappTests.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -dead_strip -bundle_loader /Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Products/Release-iphoneos/myapp.app/myapp -Xlinker -object_path_lto -Xlinker /Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Intermediates.noindex/myapp.build/Release-iphoneos/myappTests.build/Objects-normal/armv7/myappTests_lto.o -fobjc-arc -fobjc-link-runtime -lc++ -licucore -lsqlite3 -lz -framework Accelerate -framework CFNetwork -framework CoreData -framework CoreGraphics -framework CoreImage -framework CoreLocation -framework CoreTelephony -framework CoreText -framework Foundation -framework GLKit -framework ImageIO -framework OpenGLES -framework QuartzCore -framework Security -framework StoreKit -framework SystemConfiguration -framework UIKit -framework XCTest -lPods-myappTests -Xlinker -dependency_info -Xlinker /Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Intermediates.noindex/myapp.build/Release-iphoneos/myappTests.build/Objects-normal/armv7/myappTests_dependency_info.dat -o /Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Intermediates.noindex/myapp.build/Release-iphoneos/myappTests.build/Objects-normal/armv7/Binary/myappTests

ld: can't link with a main executable file '/Users/admin/Library/Developer/Xcode/DerivedData/myapp-btokobigvkxtgwgcjrapocxlexno/Build/Products/Release-iphoneos/myapp.app/myapp' for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Brittany
  • 1,359
  • 4
  • 24
  • 63
  • Post the full linker command invocation and error message (in the build tab click the lined icon on the right to expand the build command). – trojanfoe Oct 23 '19 at 06:56
  • @trojanfoe see full error message above – Brittany Oct 23 '19 at 17:17
  • Same as https://stackoverflow.com/questions/26031932/cant-link-with-a-main-executable-file – matt Oct 24 '19 at 19:50
  • Actually what I would do first is change the bundle id and see if that fixes it. If it does, try changing it back. :) – matt Oct 24 '19 at 19:50
  • The stack link answer did not resolve it for me (I already have the accepted answer's mentioned box checked) - tried the bundle ID change. No dice :/ @matt – Brittany Oct 25 '19 at 03:04

3 Answers3

35

Finally found the fix in my case. Hopefully this answer is helpful to others.

Product > Scheme > Edit Scheme, and then tap the 'Build' category on the left hand side.

Under your appTests targets, uncheck "Run".

Problem solved.

Brittany
  • 1,359
  • 4
  • 24
  • 63
  • It worked for me too. Any idea why this solution works? Adding an explanation here would be nice. – cglacet Jun 09 '22 at 09:05
1

Could you say where do you find the slashed icon - it may be a sign Xcode tries to look at a wrong path. You may easily verify it with right-click on the project from Project Navigator, show in Finder.
I recommend Changing deployment target to 8.4.
A solution might be going to Product > Scheme > Edit Scheme, choose Build and uncheck 'Run'

Viktor Varsano
  • 110
  • 1
  • 1
  • 10
0

I was getting the ld: can't link with a main executable file error because the Build Settings between my app target and the test app were different, mainly the iOS Deployment Target.

Ensuring that these two were the same allowed the build to succeed.