Afnetworking: Undefined symbols for architecture x86_64 (command line app)

Created on 29 Sep 2014  Â·  26Comments  Â·  Source: AFNetworking/AFNetworking

Hello,

I just added AFNetworking to a fresh project and got this:

Ld /Users/Ivan/Library/Developer/Xcode/DerivedData/KVC_test-buyrtupoqngjvafialtqpmqaaubh/Build/Products/Debug/KVC\ test normal x86_64
    cd "/Users/Ivan/Desktop/KVC test"
    export MACOSX_DEPLOYMENT_TARGET=10.9
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/Ivan/Library/Developer/Xcode/DerivedData/KVC_test-buyrtupoqngjvafialtqpmqaaubh/Build/Products/Debug -F/Users/Ivan/Library/Developer/Xcode/DerivedData/KVC_test-buyrtupoqngjvafialtqpmqaaubh/Build/Products/Debug -filelist /Users/Ivan/Library/Developer/Xcode/DerivedData/KVC_test-buyrtupoqngjvafialtqpmqaaubh/Build/Intermediates/KVC\ test.build/Debug/KVC\ test.build/Objects-normal/x86_64/KVC\ test.LinkFileList -mmacosx-version-min=10.9 -fobjc-arc -fobjc-link-runtime -framework CoreServices -framework SystemConfiguration -framework Security -Xlinker -dependency_info -Xlinker /Users/Ivan/Library/Developer/Xcode/DerivedData/KVC_test-buyrtupoqngjvafialtqpmqaaubh/Build/Intermediates/KVC\ test.build/Debug/KVC\ test.build/Objects-normal/x86_64/KVC\ test_dependency_info.dat -o /Users/Ivan/Library/Developer/Xcode/DerivedData/KVC_test-buyrtupoqngjvafialtqpmqaaubh/Build/Products/Debug/KVC\ test

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

Any help would be greatly appreciated..

-Ivan

Most helpful comment

@pellet Thanks! I actually got the issue resolved, but forgot to comment here. Here's what finally fixed it 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.

All 26 comments

Are you using CocoaPods to integrate AFNetworking into your project?

@mattt: Negative. I just dragged the AFNetworking folder from the zip file generated from the master branch into my project.

PD. I switched to Podfile method and now everything works fine.

platform :osx, '10.9'


source 'https://github.com/CocoaPods/Specs.git'

target "KVC test" do
  pod "AFNetworking", "~> 2.0"
end

What do you advice when I try to add AFNetworking without a dependency manager?

CocoaPods is the only supported means of installing AFNetworking as a dependency. Anyone wishing to integrate it manually is on their own.

I had the same issue @gatopan .Compare your frameworks in the "Link Binary With Libraries". In my case, the Security.framework was missing and I just added that.

Solution:
Just add -ObjC -l"Pods-AFNetworking" to your linker flag...
Linker Flags are under Build Settings tab in your XCode Project.

Reason: When you run pod install with swift project in XCode 6, it will only install pods and never add them to linker flags. With previous XCode versions, it did... I think this will solve in new cocoapods tools.

After Added -ObjC -l"Pods-AFNetworking" in linker flag... I am getting

ld: library not found for -lPods-AFNetworking
clang: error: linker command failed with exit code 1 (use -v to see invocation)???

This is for AFNetworking library dude... :)

You have to add -l"Pods-AFNetworking" only if you are using this pod library in your iOS Project.

For example, If you are using any other pod library,
let say "FMDB" Pod library, then you have to add it like this... -lPods-FMDB in your liker flags...

I get the same as @girijeshkumar2007 here. After adding it to my linker flag I get the library not found error.

The fix for this was to clear Other Linker Flags and add in ($inherited).

Hello All,
I just integrated CocoaPods in a fresh project.

Opened up workspace then also its getting crashed.

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

Anyone have solution for this?

add linker flag works, except you have to remove the "Pods-" part in XCode v6.4, like this: -l"AFNetworking"

This fails for me. I've tried adding these linker flags;
-l"AFNetworking"
-l"Pods-AFNetworking"
($inherited)

Build active architecture only is set to yes. Security Framework is included in link libraries.

No combination of the above will compile. What next?

This happens to me as well and I'm using CocoaPods

@genhau You're solution worked perfect for me. Thank you!

You are welcome :)

On Wed, Oct 14, 2015 at 12:05 PM, Christopher L. Price <
[email protected]> wrote:

@genhau https://github.com/genhau You're solution worked perfect for
me. Thank you!

—
Reply to this email directly or view it on GitHub
https://github.com/AFNetworking/AFNetworking/issues/2324#issuecomment-147951470
.

Ps for those who haven't solved this try removing all -l that have pods. That worked for me.

@ronakvora thank you!

Hello I still have the same problem. I have done all of the above but nothing
"_OBJC_CLASS_$_AFHTTPRequestOperationManager", referenced from:
objc-class-ref in HomeTableViewController.o
....
ld: symbol(s) not found for architecture arm64

Any idea?

I also have this issue and it feels like I have tried all the suggestions on this thread, as well as others I found by Googling. Any ideas? Please note that this issue only applies to Simulator builds. The linker works correctly when I build for the device.

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

@mhalttu I had the same issue, I managed to fix it by clearing my build directory of any previously built pod binaries, then rebuilt and it linked fine against the simulator.

@pellet Thanks! I actually got the issue resolved, but forgot to comment here. Here's what finally fixed it 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.

remove xcode compiled file,it works to me.

rm -rf ~/Library/Developer/Xcode/DerivedData/`

@Jasper2016 thanks u, you save my time ^^

same issue without using cocoapods, just unzip and drag file to project folder. xcode 7.3 afnetworking 3.0, solution plz .

same issue is there for me in xcode 9,

but i have different errors. When i am adding security.framework in my xcode project it will show me bunch of errors , need solution please

Was this page helpful?
0 / 5 - 0 ratings