Search code examples
objective-cxcodecocoapodsafnetworking

CocoaPods integration with CommandLineTool and Dylib targets


For test purposes, I created a new project in Xcode as a Command Line tool (Test), added a dylib target called Networking.

Ran the following commands

pod init In the pod file, under the Networking Target, Removed use_frameworks! added pod 'AFNetworking', '~> 2.0'

pod install

After Installation, In BuildPhases of Test CLI, I added Networking dylib. Created a simple method to call AFHTTPRequestOperationManager to test out. Called this method from TestCLI by Importing Networking.h

From Xcode it builds just fine, even archive works just fine from Xcode but when I try to archive from the following command line

xcodebuild -scheme Test -configuration Production archive -archivePath Test.xcarchive

I get the following error

ld: library not found for -lAFNetworking

The following build commands failed: Ld /Users/user/Library/Developer/Xcode/DerivedData/Build/Intermediates.noindex/ArchiveIntermediates/Test/InstallationBuildProductsLocation/usr/local/lib/libNetwork.dylib normal x86_64 (1 failure)

Any ideas why ?


Solution

  • Try making your build command:

    xcodebuild -workspace Test.xcworkspace -scheme Test -configuration Production archive -archivePath Test.xcarchive

    I think if you don't specify the workspace setting, xcodebuild would be trying to use your project, which would not contain any Pods or the paths needed for linking.