Xcode 4构建成功,命令行构建失败? [英] Xcode 4 build succeeds, command line build fails?
问题描述
我在Xcode 4(最新的非beta版本)中有一个项目,它在Xcode本身内置时可以很好地构建。具体来说,Ld命令正确使用派生数据目录(其中放置了构建产品,包括依赖的静态库)。
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).
但是,当我从中构建相同的项目时命令行,Ld命令失败,因为它试图使用项目中没有填充的/ build文件夹。
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.
编辑1:完整的Xcode构建命令:
Edit 1: Full Xcode build command:
xcodebuild -project AppName.xcodeproj -target AppName -configuration "Config Name"
其中 AppName
和配置名称
都是构建的正确值。
Where AppName
and Config Name
are both the correct values for the build.
编辑2:链接(Ld)命令。
内置Xcode时(这可行) :
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
使用上面的build命令从命令行构建时(这会失败):
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"
返回:
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
推荐答案
好的,几乎6个小时(可计费)小时后,我已经让构建在Xcode和命令行(以及构建服务器上)正常工作这个练习的全部内容)。
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).
一路上我会解决一个问题只是为了引起另一个问题 - 我显然会修复链接器/ Ld问题,只会导致问题在编译中(SomeClass未声明(在此函数中首次使用)或SomeHeader.h:没有此类文件或目录错误很常见)。
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:
- 转换版本以使用Xcode工作区&方案(而不是项目和目标)
- 重新安排的工作空间将App项目和静态库作为兄弟姐妹(而不是父/子)
- 更改了Xcode和工作区设置以使用目标中指定的构建位置
- 更改应用程序和库的构建产品路径以使用../build(两个项目文件都包含在主目录的兄弟子文件夹中) ,让他们构建到同一个文件夹解决了原始的链接器/ Ld命令问题,我想)
- 编辑App方案以显式构建Library目标,并在App目标之前构建它
- 在App目标的构建阶段,在Link Binary With Libraries下明确添加库
- 更改库的.a文件引用的位置类型相对于构建产品
- 向库项目添加了复制标题构建阶段,将相应的标题添加到公共部分
- 更改了Pub lic标题文件夹库项目的路径为/ include
- 将库的安装目录更改为
$(BUILT_PRODUCTS_DIR)
- 将应用目标的图书馆搜索路径和用户页眉搜索路径更改为
$(BUILT_PRODUCTS_DIR)
(递归) - 在我的Jenkins构建服务器上构建之前添加了一个Clean命令
- 为构建命令添加了显式的SDK和Arch参数
- 从构建配置名称中删除空格
- 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/20 11/04/04 / using-open-source-static-libraries-in-xcode-4 /
- https://devforums.apple.com/thread/91711?start=25&tstart=0
- 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
无论如何,我希望我已经充分利用了足够多的关键词,以后任何有类似构建问题的人都会发现这一点并发现它很有用。我不知道当我转到Xcode 4时,我在Xcode 3.x中多次使用的工作流程如此混乱,这里希望Apple能够在将来的版本中清理它。
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.
这对我来说是一次学习经历,并且经历了所有这些似乎确实解决了我之前遇到的自动完成问题。我会说事情可能会更糟;我仍然可以为SharePoint开发。
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.
这篇关于Xcode 4构建成功,命令行构建失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!