Create static library containing RestKit library

2019-04-17 08:52发布

问题:

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.

回答1:

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>


回答2:

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



回答3:

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.