Reputation: 21247
I'm totally stuck trying to run a project on the simulator using AFNetworking. I've used this dependency before on other projects, so I don't understand what is going wrong here. First, the error when I try to run the 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'm sure that this is part of the problem, but I don't know how to resolve it:
This is the offending .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 may be of interest to note that when I start typing the import line for AFNetworking, the line fills in after a few characters, so I know that there is some awareness of the presence of the AFNetworking dependency.
I installed the dependency using CocoaPods. Here is my Podfile:
# 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 am working in .xcworkspace
(not .xcodeproj
).
One more thing, my xcconfig file looks like this, which matches with 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 don't know what else to look for. I've completely removed the pod and reinstalled, only to find the exact same error. Can anyone help me figure this out? Thanks!
Upvotes: 9
Views: 7435
Reputation: 46
this happened to me too. and what I fixed it just one step:
Kill the Xcode, and right click the Xcode to show info, open it using Rosetta, then open the project to build. It works!!! By the way, I am using M1-chip Mac Mini. Before that, I tried everything I got from google, like: clean the cache, check the other linked flag, etc. they won't work for me.
I hope this can help you guys!
Upvotes: 0
Reputation: 6564
I had the same issue, when I had -lc++
already set on Other linker flags
for cpp library usage purpose.
I added these two flags -ObjC -l"AFNetworking"
on Other linker flags
, which worked and compiled successfully. These are the two flags -ObjC
and -l"AFNetworking"
. You scan add simultaneously -ObjC -l"AFNetworking"
.
Upvotes: 2
Reputation: 1347
I spent a couple of hours fighting with this exact same issue, going through all the Google hits I could find. Building for the device was working, but building for the simulator was not.
Here are the steps that finally solved the issue for me:
Clear the XCode caches:
rm -rf ~/Library/Developer/Xcode/DerivedData/
Clear the CocoaPods caches and reinstall the dependencies:
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
Finally go to the "Pods" project and set the Build Active Architectures Only
to No
also for the "Debug" configuration.
Upvotes: 25
Reputation: 968
A simple method. Download the repository file. Drag and drop the contents of the AFnetworking folder (You can create groups if necessary) then use the library. (Use #import "AFnetworking.h" )
Upvotes: -2
Reputation: 93
I would suggest you to add the $(inherited) flag into the "Build settings".
Upvotes: 4
Reputation: 21247
Well, I resolved this, but I'm not sure why it worked. I was experimenting with the Other Linker Flags in the Build Settings. I deleted the flag that was put there by the CocoaPods installation (presumably) and replaced it by copying the flag from the .xcconfig
file. Specifically, I added this text: -l"Pods-WeRun-AFNetworking"
as the second flag right after -ObjC
. It looks to me to be exactly what I had just deleted, so I really hesitate to suggest this as an 'answer', but it works now, so something must have changed.
If anyone can shed any light on this or tell me that I am fooling myself, please let me know. Thanks for the suggestions.
Upvotes: 0
Reputation: 557
Do not give version after AFNetworking in pod file. And try again. Make sure you remove the comma also.
Upvotes: 0