Xcode 4 build succeeds, command line build fails?

后端 未结 10 1597
春和景丽
春和景丽 2021-01-30 02:14

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 (wh

相关标签:
10条回答
  • 2021-01-30 02:52

    Check if you didn't import the .m files in your header files! Changing .m to .h fixed this for me!

    0 讨论(0)
  • 2021-01-30 02:53

    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.

    0 讨论(0)
  • 2021-01-30 02:57

    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!

    0 讨论(0)
  • 2021-01-30 02:58

    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

    0 讨论(0)
  • 2021-01-30 03:04

    I resolve the issue by going to "Library search path", and make sure all entries are correct.

    0 讨论(0)
  • 2021-01-30 03:07

    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.

    0 讨论(0)
提交回复
热议问题