AFNetworking will not compile

I'm completely stuck trying to run a project on a simulator using AFNetworking. I used this dependency earlier for other projects, so I don’t understand what is going on here. Firstly, an error while trying to start a project:

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_AFHTTPSessionManager", referenced from: _OBJC_CLASS_$_SharedNetworkObject in SharedNetworkObject.o "_OBJC_CLASS_$_AFJSONResponseSerializer", referenced from: objc-class-ref in SharedNetworkObject.o "_OBJC_METACLASS_$_AFHTTPSessionManager", referenced from: _OBJC_METACLASS_$_SharedNetworkObject in SharedNetworkObject.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

I am sure this is part of the problem, but I do not know how to solve it:

enter image description here

This is an abusive .h file:

 #import <Foundation/Foundation.h> #import <AFNetworking/AFNetworking.h> #import "SharedSessionKey.h" @interface SharedNetworkObject : AFHTTPSessionManager + (SharedNetworkObject *) sharedNetworkObject; // class method to return the singleton object @end 

It might seem interesting to note that when I start entering an import string for AFNetworking, the line fills after a few characters, so I know that there is some awareness about the AFNetworking dependency.

I installed the dependency using CocoaPods. Here is my subfile:

 # Uncomment this line to define a global platform for your project platform :ios, '8.0' source 'https://github.com/CocoaPods/Specs.git' target 'WeRun' do pod "AFNetworking", "2.5.2" end target 'WeRunTests' do end 

And of course, I work in .xcworkspace (not .xcodeproj ).

One more thing, my xcconfig file looks like it matches other successful AFNetworking builds:

 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/AFNetworking" OTHER_LDFLAGS = -ObjC -l"Pods-MyApp-AFNetworking" -framework "CoreGraphics" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration" OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS) PODS_ROOT = ${SRCROOT}/Pods 

I do not know what else to look for. I completely uninstalled the module and reinstalled it, only to find the same error. Can someone help me figure this out? Thanks!

+8
ios xcode cocoapods afnetworking
source share
6 answers

I spent a couple of hours battling this same problem, going through all the Google hits I could find. The building for the device worked, but there was no building for the simulator.

Here are the steps that finally solved the problem for me:

  • Clear Xcode caches:

     rm -rf ~/Library/Developer/Xcode/DerivedData/ 
  • Clear CocoaPods caches and reinstall dependencies:

     rm -rf "${HOME}/Library/Caches/CocoaPods" rm -rf "`pwd`/Pods/" pod update 
  • Finally, go to the "Pods" project and set Build Active Architectures Only to No also for the "Debug" configuration.

+24
source share

I would suggest you add the $ (inherited) flag to Build Settings.

  • Click on the blue project icon
  • Select the "Build Settings" tab.
  • In the Linking section, you'll find the Other Linker Flags option
  • add $ (inherited) to the text box
+4
source share

Do not specify the version after AFNetworking in the pod file. And try again. Make sure you also remove the comma.

0
source share

Ok, I solved it, but I'm not sure why it worked. I experimented with other Linker flags in build settings. I removed the flag that was placed there by installing CocoaPods (presumably), and replaced it by copying the flag from the .xcconfig file. In particular, I added this text: -l"Pods-WeRun-AFNetworking" as the second flag immediately after -ObjC . It seems to me that exactly what I just deleted, so I do not dare to offer this as an "answer", but it works now, so something has to change.

If anyone can shed light on this or tell me that I am fooling myself, please let me know. Thanks for the suggestions.

0
source share

I had the same problem when I had -lc++ already installed on Other linker flags to use the cpp library. I added these two -ObjC -l"AFNetworking" Other linker flags to the Other linker flags , which worked and compiled successfully. These are the two flags -ObjC and -l"AFNetworking" . Scanning is added at the same time -ObjC -l"AFNetworking" .

0
source share

A simple method. Download the repository file. Drag the contents of the AFnetworking folder (create groups if necessary), then use the library. (Use #import "AFnetworking.h")

-2
source share

All Articles