xcode iPhone SDK 链接错误与静态库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2931457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone SDK linking errors with static library
提问by Nico
I've built my own static library with components to be reused in my project, and recently had the need to update a bunch of classes. Specifically, some methods' signatures were changed due to the fact that some classes changed names.
我已经使用要在我的项目中重用的组件构建了自己的静态库,最近需要更新一堆类。具体来说,由于某些类更改了名称,因此更改了某些方法的签名。
What happens now is that the library compiles fine on its own, but, when added to an app project, the project fails to link:
现在发生的情况是该库自己编译得很好,但是,当添加到应用程序项目时,该项目无法链接:
Ld build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales normal armv6
cd /Users/nameghino/src/Sucursales
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -L/Users/nameghino/src/Sucursales/build/Debug-iphoneos -L/Users/nameghino/src/Sucursales/../../Library/MyLibraries/MSSharedLibrary-1.0.0 -F/Users/nameghino/src/Sucursales/build/Debug-iphoneos -filelist /Users/nameghino/src/Sucursales/build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales.LinkFileList -dead_strip -lxml2 -ObjC -all_load -miphoneos-version-min=3.1 -framework Foundation -framework UIKit -framework CoreGraphics -lsqlite3.0 -framework CoreLocation -framework MapKit -lxml2 /Users/nameghino/src/MSSharedComponents/Frameworks/MSSharedLibrary/build/Debug-iphoneos/libMSSharedLibrary.a -o /Users/nameghino/src/Sucursales/build/Sucursales.build/Debug-iphoneos/Sucursales.build/Objects-normal/armv6/Sucursales
Undefined symbols:
"_OBJC_CLASS_$_DataCatalogService_GetSingleRow", referenced from:
objc-class-ref-to-DataCatalogService_GetSingleRow in libMSSharedLibrary.a(MSDataCatalogSpecification.o)
**"_OBJC_CLASS_$_DataCatalogService_ArrayOfString", referenced from:
objc-class-ref-to-DataCatalogService_ArrayOfString in libMSSharedLibrary.a(MSDataCatalogSpecification.o)
"_OBJC_CLASS_$_DataCatalogService_GetSingleRowResponse", referenced from:
objc-class-ref-to-DataCatalogService_GetSingleRowResponse in libMSSharedLibrary.a(MSSingleRowResultsParser.o)
"_OBJC_CLASS_$_DataCatalogService_GetMultiRowResponse", referenced from:
objc-class-ref-to-DataCatalogService_GetMultiRowResponse in libMSSharedLibrary.a(MSMultiRowResultsParser.o)
"_OBJC_CLASS_$_DataCatalogService_GetMultiRow", referenced from:
objc-class-ref-to-DataCatalogService_GetMultiRow in libMSSharedLibrary.a(MSDataCatalogSpecification.o)
"_OBJC_CLASS_$_DataCatalogService_HelloWorldResponse", referenced from:
objc-class-ref-to-DataCatalogService_HelloWorldResponse in libMSSharedLibrary.a(DataCatalogService.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status**
The curious thing is that after a lot of project cleanups (both in the app and the lib projects), I still get the same issue. Even after starting a new project, the problem is still there.
奇怪的是,经过大量项目清理(在应用程序和 lib 项目中)后,我仍然遇到同样的问题。即使在开始一个新项目之后,问题仍然存在。
I've also taken care to restart Xcode between a clean and a build a couple of times, but no good.
我还小心地在干净和构建之间重新启动 Xcode 几次,但效果不佳。
Any ideas on where to look?
关于在哪里看的任何想法?
回答by Shaggy Frog
Have you added the library as a dependency to the project? See Xcode 3.1.1 and static libraries
您是否将库添加为项目的依赖项?请参阅Xcode 3.1.1 和静态库
If you drill down into your target, does the library name appear in the "Link binary with libraries" group?
如果深入查看目标,库名称是否出现在“将二进制文件与库链接”组中?
Look at the log for the compiler/linker output. Find the call to the linker. Does your library appear on the list of static libraries to link in?
查看编译器/链接器输出的日志。找到对链接器的调用。您的库是否出现在要链接的静态库列表中?
回答by swiftBoy
Yes I solved this error .. a Big Thanks to @Shaggy Frog
是的,我解决了这个错误……非常感谢@Shaggy Frog
Error
错误
I was using some YouTube classes and its giving me below error
我正在使用一些 YouTube 课程,它给了我以下错误
Solution
解决方案
We need to add the Lib Classes to "Compiler Sources" in "Build Phases" option.
我们需要将 Lib Classes 添加到“Build Phases”选项中的“Compiler Sources”。
Go to Project's Build Phasesand click on Compiler Sourcesoption (see below screen).
Then Add the classes here
转到 Project's Build Phases并单击Compiler Sources选项(见下图)。
然后在这里添加类
now make Project Clean and Go for Build.
现在使项目清理并进行构建。
Hope it helps :)
希望能帮助到你 :)
回答by Jeffro
I just encountered the same linker error. I discovered through trial and error that it was because I was invoking isKindOfClass. I'm not sure why this causes the linker to barf, but hopefully this information helps out.
我刚刚遇到了相同的链接器错误。我通过反复试验发现这是因为我正在调用 isKindOfClass。我不确定为什么这会导致链接器停止运行,但希望这些信息会有所帮助。
The class in question, OrderItem, is a child of NSManagedObject; in other words, it's an automatically-generated Core Data entity class.
有问题的类 OrderItem 是 NSManagedObject 的子类;换句话说,它是一个自动生成的 Core Data 实体类。
Specifically, here was the linker error:
具体来说,这是链接器错误:
"_OBJC_CLASS_$_OrderItem", referenced from:
objc-class-ref-to-OrderItem in libmyStaticLib.a(MyTableViewController.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
And here was the offending code:
这是有问题的代码:
- (void)handleButtonTapWithObject:(id)object
{
// This must be an OrderItem or else we don't want to touch it:
if ( NO == [object isKindOfClass:[OrderItem class]] ) // <-- OFFENDING CODE
{
NSLog(@"Object parameter is of unexpected type.");
return;
}
My workaround was simply to omit the test that ensures 'object' is an OrderItem. The code is not as secure without this test, but the linker error went away. I'd be curious to know if I am going about this test wrong, and perhaps there is a better way of doing this.
我的解决方法只是省略确保“对象”是 OrderItem 的测试。如果没有这个测试,代码就不那么安全了,但是链接器错误消失了。我很想知道我是否对这个测试做错了,也许有更好的方法来做到这一点。
回答by ashraf
I just found if you are using xcode 4 you should drag and drop the library project, then go to your target settings, then in the summary tab in linked frameworks and libraries add your library and done.
我刚刚发现如果您使用的是 xcode 4,您应该拖放库项目,然后转到您的目标设置,然后在链接框架和库的摘要选项卡中添加您的库并完成。
Hope it will help someone.
希望它会帮助某人。