我正在尝试构建一个静态库,我可以使用ios3.x和ios4.x。我可以用ios3.0构建一个静态库,它可以与ios3.0中的另一个项目一起工作,但不会在ios4中编译。从ios4到ios3也是如此。
以下是如何重新创建:
"TestViewController"
TestViewController *test = TestViewController alloc init;
编译
当我编译时,我得到:
Ld build/Debug-iphonesimulator/library4Test.app/library4Test normal i386
cd /Users/test/Documents/Testing/library4Test
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH "/Developer/GrandpaIPhone/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/GrandpaIPhone/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/GrandpaIPhone/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/GrandpaIPhone/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk -L/Users/test/Documents/Testing/library4Test/build/Debug-iphonesimulator -L/Users/test/Documents/Testing/library4Test -F/Users/test/Documents/Testing/library4Test/build/Debug-iphonesimulator -filelist /Users/test/Documents/Testing/library4Test/build/library4Test.build/Debug-iphonesimulator/library4Test.build/Objects-normal/i386/library4Test.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework CoreGraphics -llibrary4_1 -o /Users/test/Documents/Testing/library4Test/build/Debug-iphonesimulator/library4Test.app/library4Test
Undefined symbols:
"_objc_msgSendSuper2", referenced from:
-TestViewController didReceiveMemoryWarning in liblibrary4_1.a(TestViewController.o)
-TestViewController viewDidUnload in liblibrary4_1.a(TestViewController.o)
-TestViewController dealloc in liblibrary4_1.a(TestViewController.o)
"__objc_empty_vtable", referenced from:
_OBJC_METACLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
_OBJC_CLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
"_OBJC_CLASS_$_UIViewController", referenced from:
_OBJC_CLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
"_OBJC_METACLASS_$_UIViewController", referenced from:
_OBJC_METACLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
".objc_class_name_TestViewController", referenced from:
literal-pointer@__OBJC@__cls_refs@TestViewController in library4_1os3TestAppDelegate.o
"_OBJC_METACLASS_$_NSObject", referenced from:
_OBJC_METACLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status发布于 2010-11-29 11:17:17
不太确定,但看起来像是链接问题(所有这些.o问题)。下面是我如何设置iOS静态库的方法。这是一件很简单的事,但很有效。
部署后处理是的(检查)
安装构建产品位置/
构建静态库。默认情况下,它将构建在/usr/local/lib中
现在创建一个符号链接,方便您访问新库。一种简单的方法是打开终端并运行以下命令:
cd ~
ln -s /usr/local/lib现在打开要在其中使用库的Xcode项目。创建一个名为library或类似的组,ctrl-单击并使用“添加现有文件”来添加库。它将被称为libYourLibrary.a .a,当您运行您的项目时,您将得到一个链接错误。因此,双击项目文件,转到构建>>所有配置,并将以下值添加到“库搜索路径”设置中:~/lib
发布于 2010-11-29 12:36:58
用sdk创建一个目标的方式?我为OSx创建了一个静态库,这个过程要简单得多。
添加一个目标
当然,我必须加上一些
#if TARGET_OS_IPHONE
...
#else
...
#endif密码。你可以加上你自己的条件。
发布于 2011-06-14 20:08:26
之所以会发生编译器错误,是因为您没有链接到正确的系统框架。所有暗红色的符号都来自Foundation.framework,UIKit.framework和libobjc.dylib。
静态库不会自动提取它们需要链接的框架,所以当您使用它们时,必须自己将它们添加到项目中。
https://stackoverflow.com/questions/4006574
复制相似问题