Xcode 4 build succeeds, command line build fails? Xcode 4 build succeeds, command line build fails? ios ios

Xcode 4 build succeeds, command line build fails?


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:

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.