341
votes

I got an error when archiving a project. This is my environment.

  • Mac OS Lion
  • Xcode 4.3.1
  • iOS SDK 5.1

The project deployment target is:

IPHONEOS_DEPLOYMENT_TARGET 3.2

The error shows:

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

I guess Pods is CocoaPods that I used to manage XCode project dependencies. https://github.com/CocoaPods/CocoaPods

This is my Podfile

platform :ios  
dependency 'libPusher', '1.1'

I am not sure what the error means?

30
A cause of the problem that none of the answer covered. check this answer here: stackoverflow.com/questions/24050012/…hasan

30 Answers

621
votes

Are you opening the workspace (that was generated by CocoaPods) instead of the xcodeproj?

172
votes

I separated the app and the test targets in the Podfile by using

target :App do
    …
end

target :AppTests do
    …
end

This resulted in two new products libPods-App.a and libPods-AppTests.a, respectively and they made the previous product libPods.a obsolete. I had to remove this product from the Link Binary With Libraries Section of the Build Phases configuration of both targets.

120
votes

I ran into a similar problem today.

  1. I setup a new project
  2. I installed cocoa pods
  3. I created a new configuration Preview along with the existing Debug and Release
  4. Now when compiling on this new Preview configuration, the compiler would not be able to link with Pods and giving me this message:

    ld: library not found for -lPods
    

The solution:

What I had to do was to run

 pod install

again and thus configuring cocoapods for the new Preview configuration. It updated my project, the workspace and the Pod's project file and the problem disappeared

74
votes

Be sure that you open .xcworkspace, not .xcodeproj

53
votes

Not a solution worked for me, this is really unbearable, there's a file libpods.a(which was red coloured) I removed it and everything working fine! Cheers to me ;)

46
votes

I had divided my pod listings in the Podfile for different targets like:

target :ABC do
  pod 'KissXML', '~> 5.0'
  pod 'libPhoneNumber-iOS', '~> 0.7.2'
end

target :ABCTests do
  pod 'OCMock', '~> 2.2.1', :inhibit_warnings => true
end

And ran a pod install

This created a new library libPods-ABC.a to which my binary had to link to. But the bug was that it didn't delete the previous library i.e. libPods.a.

Solution : Remove the library libPods.a from Build Phases of Link Binary With Libraries.

46
votes

I had an old libPod.a file specified (probably caused by me changing targets).

Project Settings -> Build Phases -> Link Binary with Libraries

Usually, cocoapods would only include one library, such as libPods-target.a or libPods.a. I solved it by removing the duplicate.

44
votes

if you are running into problems with this on cocoapods v25 / Xcode 5

The Pods Xcode project now sets the ONLY_ACTIVE_ARCH build setting to YES in the Debug configuration. You will have to set the same on your project/target, otherwise the build will fail.

https://github.com/CocoaPods/CocoaPods/wiki/FAQ#running-into-build-failures-after-migrating-to-xcode-5-and-cocoapods-0250

UPDATE Make sure you have latest gems / cocoapods

  • gem update system
  • gem update cocoapods

You will want to rebuild project using Pod Install to rebuild project.

40
votes

If Xcode complains when linking, e.g. Library not found for -lPods, it doesn't detect the implicit dependencies.

Go to Product > Edit Scheme Click on Build Add the Pods static library, and make sure it's at the top of the list Clean and build again If that doesn't work, verify that the source for the spec you are trying to include has been pulled from github. Do this by looking in /Pods/. If it is empty (it should not be), verify that the ~/.cocoapods/master//.podspec has the correct git hub url in it. If still doesn't work, check your XCode build locations settings. Go to Preferences -> Locations -> Derived Data -> Advanced and set build location to “Relative to Workspace”.

http://docs.cocoapods.org/guides/getting_started.html

36
votes

I had the same problem when I edited the Podfile adding the target which I was using without a target before.

Podfile

target 'xxxx' do

pod 'xyz'
pod 'abc'    

end

After wondering around I found that under target properties >> General tab >> Linked Frameworks and Libraries section, There were the new libPods-xxxx.a and the old one libPods.a

I just removed libPods.a and everything worked fine.

27
votes

CocoaPods' wiki on GitHub has the answer right in their FAQ:

  • Go to Product > Edit Scheme
  • Click on Build
  • Add the Pods static library, and make sure it's at the top of the list
  • Clean and build again
  • If that doesn't work, verify that the source for the spec you are trying to include has been pulled from github. Do this by looking in <Project Dir>/Pods/<Name of spec you are trying to include>. If it is empty (it should not be), verify that the ~/.cocoapods/master/<spec>/<spec>.podspec has the correct github url in it.
  • If still doesn't work, check your XCode build locations settings. Go to Preferences -> Locations -> Derived Data -> Advanced and set build location to "Relative to Workspace".

Screen shot

12
votes

I was renaming the project to "NBSelector" from "Partners".

I had "Library not found for libPods-Partners" error after renaming the project. Xcode was trying to link to old Partners.a file. Just remove it if you have podInstalled after renaming.

enter image description here

11
votes

Using ONLY_ACTIVE_ARCH=NO in all pods solved the problem for me. To make this persistent, I added a post_install hook to my Podfile:

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
      target.build_configurations.each do |config|
            config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
      end
  end
end

pod install and you're done.

8
votes

Did you create 'Distribution' or similar configuration to make Ad-Hoc and App Store archives? Like many others I followed Apple's recommendations and dubbed 'Release' configuration, called it 'Distribution' and set different signing rules to it. Well, maybe that was a recommendation before they introduced schemes and "Distribute" option in Organizer, anyway, I just had it from before.

Then I had same problem with Pods. It all worked well when debugging, but archiving failed with link error. After trying this and that I changed Archive configuration of my original project from 'Distribution' to 'Release' and the link error was gone.

Yet the archive did not show up in Organizer, though I could locate it in file system, but it had 0 size.

Final step to fix all this was to change "Skip Install" setting for 'Release' configuration to "NO". Note, that you have to do this only for your main project, but not for Pods project. Better leave Pods project as is, since it's generated every time you run 'pod install'.

Update Just got an answer from CocoaPods devs It doesn't seem to work for me, since I had Pods configuration properly set. But it could help someone else.

8
votes

In my case the problem was that Xcode's Derived Data location was set to the "Legacy" option. The CocoaPods target (libPods.a) was being built correctly, but Xcode was looking in the wrong place for it.

Switching it to "Unique" (the default) solved the issue. You can do this by going to Preferences > Locations and clicking the Advanced... button.

5
votes

Only adding the "Library Search Paths" (in Build Settings of 'MyProject') to "Pods/build/Debug-iphonesimulator" worked for me (when using the simulator).

Got it from here: https://github.com/CocoaPods/CocoaPods/issues/121#issuecomment-5452473

4
votes

If you are Archiving for iOS7 and Xcode5 and got these errors, please refer to this link. It seems like Apple is dropping an architecture that cocoa pods needed https://github.com/CocoaPods/CocoaPods/pull/1352

4
votes

I found that selecting "Find implicit Dependencies" (under product / edit scheme) will resolve this issue instead of having to add pods as a target.

3
votes

I went through every answer on here, but for me it was insanely simple...Go to Target -> Build Phases, then remove libPods-YourProject.a, then add it again using the "+". Don't worry about the library being red, it's fine.

3
votes

I used old cocoapod version after update the cocoapods it suggest me to update my installed pod because of major update as i update after long time. I update it and new version pods was updated fine. But after that i got the error like library not found for -lPods-xxxprojectName-xxxxxpodName

After tried so many solutions given as answer of in this thred, non of this worked for me. Then i went to my project setting and found that pods path was change which was on Other Linker Flag

Check your Manage Schemes for correct pod name and compare it in Other Linker Flag, Change it if not similar

Old pod path was -l"lPods-xxxprojectName-xxxxxpodName"

But new pods was only xxxxxpodName so i replaced Other Linker Flag with new one like below

Changed to pod path -l"xxxxxpodName" and it's worked.

I don't know the perfect reason behind this but might be this help some one.

3
votes

I did open the workspace, but got the same error.

Build Active Architecture Only set to YES

solve my problem.

2
votes

Solved it by taking the steps below:

  • Update your cocoapods installation. ($ [sudo] gem install cocoapods)
  • Re-install your dependencies under your project. (pod install)
  • Clean and re-build / archive.
2
votes

In my case pod install fixed the problem, after creating distribution and release schemes.

1
votes

I got the same problem when archiving for submit. Discussion on this issue can be found here: https://github.com/CocoaPods/CocoaPods/issues/155

In summary, two methods work for me:

  1. Setting "Preferences -> Locations -> Advanced" to "Custom(Relative to Workspace)" OR
  2. Set Podfile to - platform :ios, :deployment_target => "5.0"
1
votes

Using Xcode 5 with iOS 7

This is what I did after being stuck for an hour. Remove ARM64 from the Build Setting > Valid Architecture.

ADDED: Also, for my case, it was not derived data location. I chose unique for build location.

1
votes

if You're using iOS7 and Xcode 5, do:

  • Select your Pods Project.
  • Go to the Target Pods and in Build Settings, select Architectures-> Standard architectures (armv7, armv7s).
  • Do the same for every Target of your Pods Project.
1
votes

I tried EVERY answer in this thread to no avail. Finally resolved my issue by matching the "Pre-Configuration Build Products Path" in my target project with the value in the Pods project. Turns out they were building to two different output locations. None of the other suggestions in this thread were relevant for me. Would be great if XCode gave a useful error description (like WHY it can't use the lib - File Not Found, No matching architecture found, etc.).

1
votes

In this issue,If you have already installed & update pod in your system then your Xcode not being able to find the Pods library.To resolve this issue, please check for following causes that may take place:

  1. You are using the workspace.
  2. The Pods library builds.
  3. The Pods library is referenced in the products group of your project.
  4. Your target includes the Pods library in the link with frameworks build phase.
1
votes

try

link_with 'YouTarget1', 'YouTarget2' ...

My project worked, the targets suddenly stopped compiling. Then added "link_with" and returned to normal.

Apparently, now it just connects to the first target, is what the link says:

http://guides.cocoapods.org/syntax/podfile.html#link_with

1
votes

If you are still getting this issue, try:

pod update

Did the work for me, hope this helps you.