ld: file not found: linker command failed with exit code 1 - ios

I've got the following error when building the project in Xcode:
ld: file not found
/Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Products/Debug-iphoneos/Social_Events.app/Social_Events
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm stuck with this error for the past hour.. Any solutions?
Code worked fine in iOS 7 and xCode 5.0. Now for iOS8 it gives me this error.
Using frameworks:
CoreTelephony
Mapkit
Facebook.SDK v3.20
Foundation
CoreGraphics
UIKit Framework
FULL ERROR:
<pre>
Ld /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Intermediates/Social_Events.build/Debug-iphoneos/Social_EventsTests.build/Objects-normal/arm64/Social_EventsTests normal arm64
cd /Users/MacBookPro/Desktop/Social_Events/Social_Events/Social_Events
export IPHONEOS_DEPLOYMENT_TARGET=7.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
</pre>
>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch arm64 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -L/Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Products/Debug-iphoneos -F/Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Products/Debug-iphoneos -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/Developer/Library/Frameworks -filelist /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Intermediates/Social_Events.build/Debug-iphoneos/Social_EventsTests.build/Objects-normal/arm64/Social_EventsTests.LinkFileList -dead_strip -bundle_loader /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Products/Debug-iphoneos/Social_Events.app/Social_Events -framework XCTest -fobjc-arc -fobjc-link-runtime -miphoneos-version-min=7.1 -framework XCTest -framework UIKit -framework Foundation -Xlinker -dependency_info -Xlinker /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Intermediates/Social_Events.build/Debug-iphoneos/Social_EventsTests.build/Objects-normal/arm64/Social_EventsTests_dependency_info.dat -o /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Intermediates/Social_Events.build/Debug-iphoneos/Social_EventsTests.build/Objects-normal/arm64/Social_EventsTests
>ld: file not found: /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Products/Debug-iphoneos/Social_Events.app/Social_Events
clang: error: linker command failed with exit code 1 (use -v to see invocation)
>(null): File not found: /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Products/Debug-iphoneos/Social_Events.app/Social_Events

You might be getting this error because you renamed your project and Tests cannot be found anymore. This is easy to fix:
Solve it in Xcode like this:
Select your project from the project navigator.
Select [Your project's Tests] under targets
Under General tab change the Host Application from the drop down
Build and run.
This problem happened to me because I renamed my project and the tests could't find it anymore.

The problem is that after renaming the product its Tests target is still looking for the previous app name.
Select your Tests target and then in Build Settings modify the TestHost values to correspond your new product name in the following way:
$(BUILT_PRODUCTS_DIR)/YourNewProductName.app/YourNewProductName

I had a similar problem -- it's because I was using Cocoapods and had opened the .xcodeproj file instead of the .xcworkspace file... doh!

I have solved it by renaming the product.
In the Application's target choose Build Settings.
Under the Packaging options, you have to rename your product to the name thats shown in the error.
It solved my problem and the code started compiling. My test cases are also executing.

Did you try cleaning up your derived data?
Xcode5->Organizer->Projects->Select your project->Delete the derived data.

Try to remove "Social_EventsTests" target.

Goto Build settings of your tests named PuzzleGameTests.
Go to Testing settings, write $(BUILT_PRODUCTS_DIR)/PuzzleGame.app/PuzzleGame
Clean and build
Note: PuzzleGame is new name of my project(product name).
RandomNumber is old name of my project(product name).

I had issue with "framework not found". It was after renaming my project.
Go to Project settings, select the target (not the project). In the General tab, find "Linked frameworks and libraries", and delete the old name.

I encountered similar problem while adding FBSDKCoreKit.framework and solution was :
If frameworks already added then remove it with option remove all references.
Drag & drop frameworks straight in the group you want it to put in project.
do not re-drag or change its location afterwords
Note: When we drag & drop frameworks in xcode it automatically set framework search path under <yourproject> -> Targets -> <yourproject> -> Search Paths -> Framework Search Paths .
once we relocate the frameworks, the Framework Search Paths becomes empty and it results in linker error , framework not found.

Had similar kind of problem when I added unit test target to my existing project. Got all sorts of error. Had to run through some loops to get it finally running. Listing them below
Make sure your entry under Header search path for test target matches that for Header Search Path in your main project folder
If you are using pods you might run in some error such 'No Module found Firebase'. For this simply add the following lines of code to your pod file and run pod install
target 'YourProjectNameTests' do
inherit! :search_paths
# Pods for testing
end
If you also get Bridging header file not found error like I did make sure you add the same for your test target in Build settings under Swift compile code general
Also you will have to follow the steps mentioned by #Jose Llausas

I had similar kind of problem when I added a framework to my project.
I have resolved the issue by removing the framework and again adding the framework to the project by dragging and dropping the framework file to the projects frameworks folder and selecting the Copy items if needed option.

Related

ld: building for tvOS, but linking in object file built for iOS, for architecture arm64

I'm building a project (the target is a framework if it's important) for tvOS and getting the error from the linker:
ld: building for tvOS, but linking in object file built for iOS, for architecture arm64
I ran otool -l *.o in OBJECTS_FILE_DIR_normal and figured out one of .o files is actually built for iOS instead of tvOS.
The problem is that there is no corresponding source file (*.mm or *.cpp) for that .o. It is called <ProjectName>_lto.o and I don't see any compiler invocations for that file in the build log. It appears only once in linker command line:
-Xlinker -object_path_lto -Xlinker /Full/path/to/<ProjectName>.build/Debug-appletvos/tvOS.build/Objects-normal/arm64/<ProjectName>_lto.o
LLVM_LTO build settings is not set explicitly, but it defaults to NO. Setting it to NO explicitly doesn't help.
I'm using Xcode 8.3.2 (8E2002).
So my question is: why is this object file created at all and why is it created for wrong target platform?
Not sure if this should be the answer to my own question or the edit, as it doesn't answer the original question "why that _lto.o file is generated at all for wrong arch with LLVM_LTO=NO", but it may help others troubleshoot this issue.
So I decided to try enabling LTO in the project. LLVM_LTO=YES_THIN behaved identically to LLVM_LTO=NO. LLVM_LTO=YES made linker produce tons of warnings like the following:
ld: warning: Linking two modules of different target triples: /path/to/one/of/3rdpary/libs/libproblematic.a(file1.o)' is 'arm64-apple-ios7.0.0' whereas 'ld-temp.o' is 'arm64-apple-tvos9.0.0'
ld: warning: Linking two modules of different target triples: /path/to/one/of/3rdpary/libs/libproblematic.a(file2.o)' is 'arm64-apple-ios7.0.0' whereas 'ld-temp.o' is 'arm64-apple-tvos9.0.0'
But with all those warnings for some weird reason the link succeeded. The interesting thing is that if I run otool -l libproblematic.a, I only see cmd LC_VERSION_MIN_TVOS lines and no cmd LC_VERSION_MIN_IPHONEOS and linker didn't complain on any of the objects from that library that they were built for wrong target platform. Also file1, file2, etc. do not appear in the output of otool -l libproblematic.a.

Xcode 7 build failed: ld: library not found for -lGoogleAnalyticsServices

Every time when I open my app with Xcode I get this error:
ld: library not found for -lGoogleAnalyticsServices
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Then I need to unmark the target on the libGoogleAnalyticsServices.a file and mark it on again. After the uncheck/check of the target the app runs normally...
I get 2 other warning when this happens:
ld: warning: directory not found for option '-L/Users/vision/Documents/Apps/Mijn Cijfers/Mijn'
ld: warning: directory not found for option '-LCijfers'
Now this looks like Xcode can't read spaces and looks for a new directory called Cijfers. My app is called: Mijn Cijfers, but I never had this problem before with spaces in my project name.
Every time when I check/uncheck the target of libGoogleAnalyticsServices.a the Library Search Path is adding new rows:
I think both cases has to do something with the warnings and errors that I get. It's really annoying to remove the Library Search Paths and check/uncheck the target to let my app run normally. -.-
Does anyone know a solution to solve this odd bug?
You need to delete all these path except the "$inherited" and then add Google Analytics library path (Drag the folder where you saved the library).
If you follow this then you don't need to recheck/uncheck the library path.
If you have just created pod file by running $ pod init command in terminal,
then just close project and Open projectName.xcworkspace instead of projectName.xcodeproj
which will not throw error -lxyzLibray eg. -lJSONModel not found.
Now compile and debug again It will work.

AFNetworking won't compile

I'm totally stuck trying to run a project on the simulator using AFNetworking. I've used this dependency before on other projects, so I don't understand what is going wrong here. First, the error when I try to run the project:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_AFHTTPSessionManager", referenced from:
_OBJC_CLASS_$_SharedNetworkObject in SharedNetworkObject.o
"_OBJC_CLASS_$_AFJSONResponseSerializer", referenced from:
objc-class-ref in SharedNetworkObject.o
"_OBJC_METACLASS_$_AFHTTPSessionManager", referenced from:
_OBJC_METACLASS_$_SharedNetworkObject in SharedNetworkObject.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm sure that this is part of the problem, but I don't know how to resolve it:
This is the offending .h file:
#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>
#import "SharedSessionKey.h"
#interface SharedNetworkObject : AFHTTPSessionManager
+ (SharedNetworkObject *) sharedNetworkObject; // class method to return the singleton object
#end
It may be of interest to note that when I start typing the import line for AFNetworking, the line fills in after a few characters, so I know that there is some awareness of the presence of the AFNetworking dependency.
I installed the dependency using CocoaPods. Here is my Podfile:
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
source 'https://github.com/CocoaPods/Specs.git'
target 'WeRun' do
pod "AFNetworking", "2.5.2"
end
target 'WeRunTests' do
end
And, of course I am working in .xcworkspace (not .xcodeproj).
One more thing, my xcconfig file looks like this, which matches with other successful AFNetworking builds:
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/AFNetworking"
OTHER_LDFLAGS = -ObjC -l"Pods-MyApp-AFNetworking" -framework "CoreGraphics" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration"
OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)
PODS_ROOT = ${SRCROOT}/Pods
I don't know what else to look for. I've completely removed the pod and reinstalled, only to find the exact same error. Can anyone help me figure this out? Thanks!
I spent a couple of hours fighting with this exact same issue, going through all the Google hits I could find. Building for the device was working, but building for the simulator was not.
Here are the steps that finally solved the issue for me:
Clear the XCode caches:
rm -rf ~/Library/Developer/Xcode/DerivedData/
Clear the CocoaPods caches and reinstall the dependencies:
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
Finally go to the "Pods" project and set the Build Active Architectures Only to No also for the "Debug" configuration.
I would suggest you to add the $(inherited) flag into the "Build settings".
Tap on the blue project icon
Select "Build settings" tab
Under "Linking" you'll find a setting called "Other Linker Flags"
add $(inherited) into the textfield
I had the same issue, when I had -lc++ already set on Other linker flags for cpp library usage purpose.
I added these two flags -ObjC -l"AFNetworking" on Other linker flags, which worked and compiled successfully. These are the two flags -ObjC and -l"AFNetworking". You scan add simultaneously -ObjC -l"AFNetworking".
Do not give version after AFNetworking in pod file. And try again. Make sure you remove the comma also.
Well, I resolved this, but I'm not sure why it worked. I was experimenting with the Other Linker Flags in the Build Settings. I deleted the flag that was put there by the CocoaPods installation (presumably) and replaced it by copying the flag from the .xcconfig file. Specifically, I added this text: -l"Pods-WeRun-AFNetworking" as the second flag right after -ObjC. It looks to me to be exactly what I had just deleted, so I really hesitate to suggest this as an 'answer', but it works now, so something must have changed.
If anyone can shed any light on this or tell me that I am fooling myself, please let me know. Thanks for the suggestions.
this happened to me too. and what I fixed it just one step:
Kill the Xcode, and right click the Xcode to show info, open it using Rosetta, then open the project to build. It works!!!
By the way, I am using M1-chip Mac Mini.
Before that, I tried everything I got from google, like: clean the cache, check the other linked flag, etc. they won't work for me.
I hope this can help you guys!
A simple method. Download the repository file. Drag and drop the contents of the AFnetworking folder (You can create groups if necessary) then use the library. (Use #import "AFnetworking.h" )

Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS

Starting from some point in the past xCode 4 in complaining about linker problems:
ld: warning: building for MacOSX, but linking against dylib built for
iOS:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks//CoreGraphics.framework/CoreGraphics
I have checked everything but still nothing suspicious in the config and it compiles and runs.
The only thing that I see it is double slashes before CoreGraphics.framework, why I do not know. Tried remove and add again library on "Build phases" that did not help.
Sometimes it's easier to debug Xcode problems by looking at the build log for the command lines it's using.
If you're building from the command line, you can get that message if you don't specify -miphoneos-version-min=
This compiles:
(where conftest.c just contains int main() {})
/Applications/Xcode5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -miphoneos-version-min=6.0 conftest.c
And this gives the error:
/Applications/Xcode5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk --sysroot /Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk conftest.c
ld: building for MacOSX, but linking against dylib built for iOS Simulator file '/Applications/Xcode5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk/usr/lib/libSystem.dylib' for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Check your Framework Search Paths for your Main target and your test Target.
I had a lot of crap in mine.
had old project written in XCode 4 and just started to use Unit Tests in XCode 5.
Here's the minimum I have to get my test project to run
Project Navigator > click on project at top >
Targets > Build Settings > Framework Search Paths
TARGET:my_project
$(inherited)
"$(SRCROOT)"
"$(SRCROOT)/my_project"
TEST:my_projectTests
"$(SDKROOT)/Developer/Library/Frameworks" <<XCTest.framework is here
"$(DEVELOPER_LIBRARY_DIR)/Frameworks"
"$(SRCROOT)/.."
"$(SRCROOT)" << Documents/my_project
"$(SRCROOT)/my_project" << Documents/my_project/my_project
where directory structure is
Documents/my_project
my_project.xcodeproj
/my_project
Note: If you drag a framework into XCode. XCode 5 has bad habit of hardcoding the path
/Users/gbxc/Documents/my_project
should be
"$(SRCROOT)" << Documents/my_project
"$(SRCROOT)/my_project" << Documents/my_project/my_project
so if you moved your project might get problems
Best way to check whats correct is to create a new single view project that runs tests ok.
Run the Test action
By default it fails but at least testing is running
then compare the Framework Search Paths.
If you're using Carthage and compiling a Mac app, search on your project's Framework Search Paths you might find something like $(PROJECT_DIR)/Carthage/Build/iOS.
Removing that fixed my issue.
This issue is due to include a wrong framework version in Xcode. The project is built for Mac OS X, but it uses iOS version's framework.

Xcode 4 build succeeds, command line build fails?

I have a project in Xcode 4 (the latest non-beta version) that builds fine when built in Xcode itself. Specifically, the Ld command correctly uses the derived data directory (where build products, including a dependent static library, are placed).
However, when I build the same project from the command line, the Ld command fails, as it is trying to use the /build folder within the project, which is not being populated.
I've tried adjusting every build setting I know about, both in the parent and the dependent project.
Any ideas on where to start debugging this? I can provide more info as needed.
Edit 1: Full Xcode build command:
xcodebuild -project AppName.xcodeproj -target AppName -configuration "Config Name"
Where AppName and Config Name are both the correct values for the build.
Edit 2: Link (Ld) commands.
When built in Xcode (this works):
Ld /Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator/AppName.app/AppName normal i386
cd /Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -L/Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator -L/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName -F/Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator -filelist /Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Intermediates/AppName.build/Debug-iphonesimulator/AppName.build/Objects-normal/i386/AppName.LinkFileList -mmacosx-version-min=10.6 -lxml2 -all_load -ObjC -licucore -Xlinker -objc_abi_version -Xlinker 2 -lMyClientLibrary -lxml2 -lsqlite3.0 -framework Security -framework MessageUI -framework QuartzCore -framework MediaPlayer -framework MapKit -framework CoreLocation -framework AudioToolbox -lz.1.2.3 -framework MobileCoreServices -framework SystemConfiguration -framework CFNetwork -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator/AppName.app/AppName
When built from command line using build command above (this fails):
Ld "build/AppName.build/Prod Ad Hoc-iphoneos/AppName.build/Objects-normal/armv6/AppName" normal armv6
cd /Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName
setenv IPHONEOS_DEPLOYMENT_TARGET 4.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk "-L/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/Prod Ad Hoc-iphoneos" -L/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName "-F/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/Prod Ad Hoc-iphoneos" -filelist "/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/AppName.build/Prod Ad Hoc-iphoneos/AppName.build/Objects-normal/armv6/AppName.LinkFileList" -dead_strip -lxml2 -all_load -ObjC -licucore -miphoneos-version-min=4.0 -lMyClientLibrary -lxml2 -lsqlite3.0 -framework Security -framework MessageUI -framework QuartzCore -framework MediaPlayer -framework MapKit -framework CoreLocation -framework AudioToolbox -lz.1.2.3 -framework MobileCoreServices -framework SystemConfiguration -framework CFNetwork -framework UIKit -framework Foundation -framework CoreGraphics -o "/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/AppName.build/Prod Ad Hoc-iphoneos/AppName.build/Objects-normal/armv6/AppName"
Which returns:
ld: library not found for -lMyClientLibrary
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
Ok, so nearly 6 (billable) hours later, I've gotten the build to work correctly in Xcode and on the command line (and on the build server, the whole point of this exercise).
Along the way I would fix one problem just to cause another - I would apparently fix the linker/Ld problem, only to cause problems in compilation ("SomeClass undeclared (first use in this function)" or "SomeHeader.h: No such file or directory" errors were common).
It was one of those times that I adjusted nearly every setting I could find, so it's hard to say what exactly what wrong and what exactly fixed it.
Things I think might have helped are are as follows:
Converted build to use an Xcode workspace & scheme (instead of project & target)
Rearranged workspace to have the App project and static library as siblings (not as parent/child)
Changed Xcode and workspace settings to use build locations specified in targets
Change Build Products Path for App and Library to use ../build (both project files are contained in sibling subfolders of a master directory, so having them build into the same folder solved the original linker/Ld command problem, I think)
Edited the App scheme to explicitly build the Library target, and build it before the App target
In the Build Phases for the App target, explicitly add the Library under "Link Binary With Libraries"
Change the location type of the Library's .a file reference to "Relative to Build Products"
Added a "Copy Headers" build phase to the Library project, added the appropriate headers to the Public section
Changed the Public Headers Folder Path of the Library project to "/include"
Changed the Installation Directory of the Library to $(BUILT_PRODUCTS_DIR)
Changed the Library Search Paths and the User Header Search Paths of the App target to $(BUILT_PRODUCTS_DIR) (recursive)
Added a Clean command before the build on my Jenkins build server
Added explicit SDK and Arch arguments to the build command
Removed spaces from build configuration name
Final build command looks like this:
xcodebuild -workspace ClientName.xcworkspace -scheme AppName -configuration "ProdAdHoc" -sdk iphoneos -arch "armv6 armv7"
Some useful resources I used while debugging this issue:
http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/
https://devforums.apple.com/thread/91711?start=25&tstart=0
Anyway, I hope I've peppered enough keywords above that anybody who has any similar build issues in the future stumbles upon this and finds it useful. I have no clue how a workflow I did many times in Xcode 3.x got so messed up when I moved to Xcode 4, here's hoping Apple is able to clean this up in future releases.
This was a heck of a learning experience for me, and going through all of this did seem to clear up issues with autocomplete I was having beforehand. I will say things could have been much worse; I could still be developing for SharePoint.
I ran in to the same issue yesterday and was able to work it out. In an effort to narrow down what worked for James, I'll point to what I had to do. I had to add a workspace and switch to running xcodebuild with workspace/scheme instead of project/target.
Using workspace/scheme forced xcodebuild to use the DerivedData folder instead of the build output folder under the main project. This allowed the linker to find the associated static library.
This blog post was hugely helpful:
http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/
I got this error when I was experimenting with my files I add the #implementation to the .h file and left the .m file empty. I don't believe this is your error but if anyone else gets it maybe check that you haven't done this.
Check if you didn't import the .m files in your header files! Changing .m to .h fixed this for me!
I don't know if this will work for you but in my case, I had more than one main.m file. All I had to do was detach one of the main.m from the target and it worked. Make sure you don't have more than one main.m in your project.
If you look at the log of the build, asking to see all messages, you should see a terse line that says "link ..." that has little in the way of details. However if you right click that line and select "expand all transcripts" you get a very detailed line telling you what command was issued from within XCode.
That should help you to debug the issue.
Dave
I had a similar exception encountered,
it turn out that i got some (null) reference in project.pbxproj
after I clean up those null reference in the project.pbxproj, the command line build was success just like the xcode previously does.
Take a look at Xcode 4 project: utility to clean up pbxproj file?
utility-to-clean-up-pbxproj-file
for more reference
All of a sudden I got the same problem after a Clean, at first I panicked wen I watched:
linker command failed with exit code 1 (use -v to see invocation)
... but it turned to be really easy to fix, no command line needed!
I clicked on my project's root (the one on the top with the blueprint icon with an "A") in the Navigator, then clicked the PROJECT section (you can click on the TARGET section as well) and then clicked the button in the bottom-middle called "Validate Settings".
XCode itself validated the project files and told me that the problem was a duplicated target definition, and offered to fix it... and voilá, the problem its gone!
Good luck!
I resolve the issue by going to "Library search path", and make sure all entries are correct.
Personally, I had this issue when I was developing a static library. I had the static library target with all the production code, and a test target that pulled in the MyStaticLib.a file as a framework.
Tests ran just fine in Xcode, but not in the terminal using xcodebuild. The problem ended up being that the static library target was compiling for Standard architectures, while the test target wanted to compile for Standard architectures (including 64-bit). Switching the test target to Standard architectures fixed everything.

Resources