创建包含 RestKit 库的静态库

发布于 2024-12-14 10:54:39 字数 3760 浏览 2 评论 0原文

我在使用 RestKit 库时遇到另一个问题。

我的目标是为我的公司创建一个特定的库,可用于所有 IOS 开发项目。

为此,我创建了一个库,在其中导入了 RestKIt 库。 我遵循 RestKit xCode 4.x 的安装指南。

因此,我创建了一个新项目,在其中导入了名为“m2mBackEnd”的库。

在我使用该库的测试项目中,我做了 Oppers 以下操作:

1 - 我导入了库“m2mBackEnd”。

2 - 在“构建设置/其他链接器标志”中,我添加了“-ObjC”。

3 - 在“构建设置/用户标题搜索路径”中,我添加了包含所有 '.哈。

4 - 在“构建阶段/目标依赖项”中,我添加了对“m2mBackEnd”的依赖项

5 - 在“构建阶段/将二进制文件与库链接”中,我添加了“libm2mBackEnd.a”。

但它不起作用我遇到错误:

undefined symbols for architecture i386:
"_CFHTTPMessageCreateRequest", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_CFHTTPMessageAddAuthentication", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_CFHTTPMessageCopyHeaderFieldValue", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_kCFHTTPAuthenticationSchemeBasic", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_kCFHTTPVersion1_1", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_SCNetworkReachabilityCreateWithAddress", referenced from:
  -[RKReachabilityObserver initWithAddress:] in    libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityCreateWithName", referenced from:
  -[RKReachabilityObserver initWithHost:] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityGetFlags", referenced from:
  -[RKReachabilityObserver getFlags] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilitySetCallback", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCError", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
  -[RKReachabilityObserver unscheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCErrorString", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
  -[RKReachabilityObserver unscheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilitySetDispatchQueue", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
  -[RKReachabilityObserver unscheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_UTTypeCreatePreferredIdentifierForTag", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_UTTypeCopyPreferredTagWithClass", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_kUTTagClassFilenameExtension", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_kUTTagClassMIMEType", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_xmlNodeGetContent", referenced from:
  -[RKXMLParserLibXML parseNode:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlNewParserCtxt", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlParseMemory", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlFreeDoc", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlFreeParserCtxt", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlFree", referenced from:
  -[RKXMLParserLibXML parseNode:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我错过了什么吗?或者做错了什么?

是否可以使用 RestKit 创建库?

感谢您的帮助。

I have another problem in my use of RestKit Library.

My goal is to create a specific library for my company, which can be used for all IOS development projects.

For this I created a library in which I imported the library RestKIt.
I followed the installation guide for RestKit xCode 4.x.

So I then created a new project in which I imported my library named "m2mBackEnd".

In my test project that uses the library, I did Oppers the following:

1 - I imported the library "m2mBackEnd".

2 - In "Build Settings / Other Linker Flags" I added "-ObjC".

3 - In "Build Settings / User Header Search Paths" I added the folder that contains all '. h'.

4 - In "Build Phases / Target Dependencies" I added the dependency to "m2mBackEnd"

5 - In "Build Phases / Link Binary With Libraries" I added "libm2mBackEnd.a".

But it does not work I encounter errors:

undefined symbols for architecture i386:
"_CFHTTPMessageCreateRequest", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_CFHTTPMessageAddAuthentication", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_CFHTTPMessageCopyHeaderFieldValue", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_kCFHTTPAuthenticationSchemeBasic", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_kCFHTTPVersion1_1", referenced from:
  -[RKRequest addHeadersToRequest] in libm2mBackEnd.a(RKRequest.o)
"_SCNetworkReachabilityCreateWithAddress", referenced from:
  -[RKReachabilityObserver initWithAddress:] in    libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityCreateWithName", referenced from:
  -[RKReachabilityObserver initWithHost:] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilityGetFlags", referenced from:
  -[RKReachabilityObserver getFlags] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilitySetCallback", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCError", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
  -[RKReachabilityObserver unscheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCErrorString", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
  -[RKReachabilityObserver unscheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_SCNetworkReachabilitySetDispatchQueue", referenced from:
  -[RKReachabilityObserver scheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
  -[RKReachabilityObserver unscheduleObserver] in libm2mBackEnd.a(RKReachabilityObserver.o)
"_UTTypeCreatePreferredIdentifierForTag", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_UTTypeCopyPreferredTagWithClass", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_kUTTagClassFilenameExtension", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_kUTTagClassMIMEType", referenced from:
  -[NSString(RestKit) MIMETypeForPathExtension] in libm2mBackEnd.a(NSString+RestKit.o)
"_xmlNodeGetContent", referenced from:
  -[RKXMLParserLibXML parseNode:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlNewParserCtxt", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlParseMemory", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlFreeDoc", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlFreeParserCtxt", referenced from:
  -[RKXMLParserLibXML parseXML:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
"_xmlFree", referenced from:
  -[RKXMLParserLibXML parseNode:] in libm2mBackEnd.a(RKXMLParserLibXML.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Do I miss something? Or done something wrong?

Is it possible to create a library using RestKit?

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

末蓝 2024-12-21 10:54:39

我希望您此时已经解决了该问题,如果没有尝试以下安装步骤,

请检查您是否完成了自述文件中提到的安装步骤,并添加了其中提到的所有框架,以及中提到的更改构建设置

Xcode 4.x(Git 子模块)

  1. 添加子模块: git submodule add git://github.com/RestKit/RestKit.git RestKit
  2. 在 Xcode 中打开要添加 RestKit 的项目。
  3. 聚焦您的项目并选择“查看”菜单 > “导航员”> “项目”可查看项目文件列表。
  4. 将 RestKit.xcodeproj 文件从 Finder 拖放到“”.xcodeproj 上。
  5. 单击左侧边栏中的项目名称,以在窗口右侧窗格中打开项目设置视图。
  6. 在中间窗格中,您将看到项目的 PROJECTTARGETS 标题。单击您的项目名称,然后选择顶部的构建设置,打开整个项目的构建设置编辑器。
  7. 找到标头搜索路径设置。双击并添加一个新条目。将搜索路径添加到已添加到项目中的 "$(SOURCE_ROOT)/RestKit/Build" 目录。 请勿选中递归复选框。
  8. 找到库搜索路径设置。双击并添加一个新条目。将搜索路径添加到已添加到项目中的“$(SOURCE_ROOT)/RestKit/Build/$(BUILD_STYLE)-$(PLATFORM_NAME)” 目录。
    注意:仅当您使用 DerivedData 时才需要这样做。
  9. 找到其他链接器标志条目并双击它。使用+按钮添加新条目并输入-ObjC -all_load。使用完成按钮关闭编辑器。
  10. 在编辑器窗格中间的 TARGETS 列表中找到您想要添加 RestKit 的目标。选择它以在窗口的右窗格中打开目标设置编辑器。
  11. 单击窗口顶部的构建阶段选项卡以打开构建阶段编辑器。
  12. 单击目标依赖项将二进制文件与库链接项旁边的显示三角形。
  13. 目标依赖项部分中,单击+按钮打开目标选择表。单击RestKit聚合目标(它将具有靶心图标),然后单击添加按钮创建依赖项。
  14. 将二进制文件与库链接部分中,单击+按钮打开库选择表。在这里,我们需要指示目标链接所有必需的 RestKit 库和几个系统库。选择以下每一项(一次一项或按住 Command 键一次选择所有项),然后单击添加按钮:
    • libRestKitCoreData.a - 可选。仅当您使用核心数据时才需要。
    • libRestKitJSONParserJSONKit.a
    • libRestKitNetwork.a
    • libRestKitObjectMapping.a
    • libRestKitSupport.a
    • CFNetwork.framework
    • CoreData.framework - 可选。仅当您使用核心数据时才需要
    • MobileCoreServices.framework
    • SystemConfiguration.framework
    • libxml2.dylib - 可选。仅当您从 XML 有效负载进行映射并将 libRestKitXMLParserLibxml.a 链接到您的应用时才需要。
  15. 在继续之前,请验证所有库是否都显示在将二进制文件与库链接部分中。

恭喜,您现在已完成将 RestKit 添加到基于 Xcode 4 的项目中!

现在,您只需在应用程序中的适当位置添加 RestKit 库的包含内容即可。相关内容包括:

#import <RestKit/RestKit.h>
// And if you are using Core Data...
#import <RestKit/CoreData/CoreData.h>

I hope you would have resolved the issue by this time, If not try the below installation steps

Check whether you completed installation steps as mentioned in the read me file, and added all the frame work mentioned in it, as well as changes mentioned in the Build setting

Xcode 4.x (Git Submodule)

  1. Add the submodule: git submodule add git://github.com/RestKit/RestKit.git RestKit
  2. Open the project you wish to add RestKit to in Xcode.
  3. Focus your project and select the "View" menu > "Navigators" > "Project" to bring the project file list into view.
  4. Drag the RestKit.xcodeproj file from the Finder and drop it on your "".xcodeproj.
  5. Click on your project's name in the sidebar on the left to open the project settings view in the right pane of the window.
  6. In the middle pane you will see PROJECT and TARGETS headers for your project. Click on your project name, then select Build Settings along the top to open the Build Settings editor for your entire project.
  7. Find the Header Search Paths setting. Double click and add a new entry. Add a search path to the "$(SOURCE_ROOT)/RestKit/Build" directory you have added to your project. DO NOT check the Recursive checkbox.
  8. Find the Library Search Paths setting. Double click and add a new entry. Add a search path to the "$(SOURCE_ROOT)/RestKit/Build/$(BUILD_STYLE)-$(PLATFORM_NAME)" directory you have added to your project.
    NOTE: This is only necessary if you are NOT using DerivedData.
  9. Find the Other Linker Flags entry and double click it. Use the + button to add a new entry and enter -ObjC -all_load. Dismiss the editor with the Done button.
  10. Locate the target you wish to add RestKit to in the TARGETS list in the middle of the editor pane. Select it to open the target settings editor in the right pane of the window.
  11. Click the Build Phases tab along the top of the window to open the Build Phases editor.
  12. Click the disclosure triangles next to the Target Dependencies and Link Binary with Libraries items.
  13. In the Target Dependencies section, click the + button to open the Target selection sheet. Click on the RestKit aggregate target (it will have the bulls-eye icon) and click the Add button to create a dependency.
  14. In the Link Binary with Libraries section, click the + button to open the Library selection sheet. Here we need to instruct the target to link against all the required RestKit libraries and several system libraries. Select each of the following items (one at a time or while holding down the Command key to select all of them at once) and then click the Add button:
    • libRestKitCoreData.a - Optional. Only necessary if you are using Core Data.
    • libRestKitJSONParserJSONKit.a
    • libRestKitNetwork.a
    • libRestKitObjectMapping.a
    • libRestKitSupport.a
    • CFNetwork.framework
    • CoreData.framework - Optional. Only necessary if you are using Core Data
    • MobileCoreServices.framework
    • SystemConfiguration.framework
    • libxml2.dylib - Optional. Only necessary if you are mapping from XML payloads and link libRestKitXMLParserLibxml.a into your app.
  15. Verify that all of the libraries are showing up in the Link Binary with Libraries section before continuing.

Congratulations, you are now done adding RestKit into your Xcode 4 based project!

You now only need to add includes for the RestKit libraries at the appropriate places in your application. The relevant includes are:

#import <RestKit/RestKit.h>
// And if you are using Core Data...
#import <RestKit/CoreData/CoreData.h>
尝蛊 2024-12-21 10:54:39

尝试将 CFNetwork.framework 添加到项目的目标中(为我解决了前 6 个错误)

Try Adding CFNetwork.framework to your project's target (resolved the first 6 errors for me)

痴情 2024-12-21 10:54:39

安装 RestKit 的推荐方法是通过 CocoaPods 包管理器,因为它提供灵活的依赖管理和非常简单的安装。为了获得最佳效果,建议您通过 CocoaPods >= 0.19.1 使用 Git 安装 >= 1.8.0 通过 Homebrew< 安装/a>.

安装 CocoaPods(如果尚未可用):

$ [sudo] gem install cocoapods
$ pod setup

更改到 Xcode 项目的目录,然后创建并编辑 Podfile 并添加 RestKit:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile

platform :ios, '5.0' 
# Or platform :osx, '10.7'
pod 'RestKit', '~> 0.20.0'

# Testing and Search are optional components
pod 'RestKit/Testing', '~> 0.20.0'
pod 'RestKit/Search',  '~> 0.20.0'

安装到项目中:

$ pod install

从 .xcworkspace 文件(不是通常的项目文件)在 Xcode 中打开项目

$ open MyProject.xcworkspace

请注意如果您的安装失败,可能是因为您安装的 Git 版本低于 CocoaPods期待。请通过执行 git --version 确保您运行的 Git >= 1.8.0。您可以通过执行 pod install --verbose 来全面了解安装详细信息。

The recommended approach for installing RestKit is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.19.1 using Git >= 1.8.0 installed via Homebrew.

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Change to the directory of your Xcode project, and Create and Edit your Podfile and add RestKit:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile

platform :ios, '5.0' 
# Or platform :osx, '10.7'
pod 'RestKit', '~> 0.20.0'

# Testing and Search are optional components
pod 'RestKit/Testing', '~> 0.20.0'
pod 'RestKit/Search',  '~> 0.20.0'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file)

$ open MyProject.xcworkspace

Please note that if your installation fails, it may be because you are installing with a version of Git lower than CocoaPods is expecting. Please ensure that you are running Git >= 1.8.0 by executing git --version. You can get a full picture of the installation details by executing pod install --verbose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文