347

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?

Besi
  • 22,579
  • 24
  • 131
  • 223
angelokh
  • 9,426
  • 9
  • 69
  • 139
  • A cause of the problem that none of the answer covered. check this answer here: https://stackoverflow.com/questions/24050012/error-library-not-found-for/29497314#29497314 – hasan Oct 01 '17 at 10:22

42 Answers42

623

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

alloy
  • 20,908
  • 2
  • 30
  • 40
  • 28
    I did. The problem is resolved after changing Pods project's release architecture to 'armv6 armv7'. – angelokh Apr 05 '12 at 05:32
  • 11
    Aha, in your `Podfile`, specify the platform like so: `platform :ios, :deployment_target => "3.2"`. That should configure it correctly the next time you run `pod install`. – alloy Apr 05 '12 at 21:54
  • 254
    To be clear for newbies out there, you should be opening the `.xcworkspace` file, not the `.xcodeproj`. This way in addition to your project, Xcode knows about the project in the `Pods/` directory and how to build `libPods.a`. – Jonathan Tran Jul 08 '13 at 00:59
  • 13
    Following on from @JonathanTran's comment... if you have the `.xcodeproj` open you need to have it closed before you open the `.xcworkspace` file. – Ross Sep 18 '13 at 19:25
  • 4
    Note that the project you're using pods with should also have it's architecture set to armv6 armv7(if thats the option you're using on pods project architecture). If you don't do that you'll get the very same error. – Patrick Bassut May 26 '14 at 06:16
  • Another case might be when under "Product-.Scheme-.Edit Schema", wrong destination is selected. In my case it was 32 bit architecture iOS. I changed it to iPhone 64 bit and it worked. Hope this helps ) – sermilion Aug 15 '14 at 20:25
  • There was a mixup somewhere while install pods with xcode open. I restarted xcode and viola, pods was in the existing workspace. – Jacksonkr Aug 22 '17 at 14:50
  • 1
    Thank you. Why is this not mentioned in the CLI when running pod install? – Petrus Theron May 30 '18 at 16:09
172

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.

Andras Hatvani
  • 4,346
  • 4
  • 29
  • 45
  • 3
    Yes, this was it for me, after trying a dozen other things earlier in this thread. My podfile has two targets as above, and so libPods.a was not being built. Deleting libPods.a from the Link Binary With Libraries section "fixed" it (though of course I now have 32 "Undefined symbols" messages to sort through, due to a missing SQLite lib, etc. – Hot Licks Nov 11 '14 at 22:37
  • This is the same fix as http://stackoverflow.com/a/21694261/581994 and a couple of others. – Hot Licks Nov 11 '14 at 22:56
  • Currently still an issue that occurs – nsantorello Aug 05 '15 at 16:43
  • "they made the previous product libPods.a obsolete. I had to remove..." – Vassily Nov 23 '15 at 13:32
  • This was mostly the issue for me. For some reason, I had a binary from an older test target in there as well. – LJ Wilson May 25 '16 at 16:36
  • Thank you very mach! Removing "libPods-OldTargetName.a" helps me – Алексей Алыбин Nov 27 '16 at 17:27
120

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

Besi
  • 22,579
  • 24
  • 131
  • 223
  • 1
    This caught me out as well. Particular as it continued working long after I created the configurations and it was only when I cleaned out my derived data that the issue occurred. – Daniel Wood Oct 21 '14 at 13:29
  • And pay attention to the warnings displayed in the "Sending stats" section of the output of either "pod install --verbose" or "pod update --verbose", such as "The \`yourApp [Debug]\` target overrides the \`HEADER_SEARCH_PATHS\` build setting defined in ..." or "... target overrides the \`OTHER_LDFLAGS\` build setting ...". – jk7 Mar 23 '16 at 02:28
  • change **Preview** configuration in **Per-configuration Build Products Path**, and then do **pod install**, pod doesnt save my value in pod project, any help? – liu pluto May 12 '18 at 08:25
  • Ah! The problem was occurring just after creating a new configurations for Extensions. First 3 steps help me to understand the issue. Thanks! – iHarshil Aug 23 '19 at 09:56
74

Be sure that you open .xcworkspace, not .xcodeproj

Hima
  • 1,249
  • 1
  • 14
  • 18
Michal Gumny
  • 1,770
  • 1
  • 16
  • 24
56

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 ;)

Hemang
  • 26,840
  • 19
  • 119
  • 186
47

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.

Sebastian Hojas
  • 4,158
  • 2
  • 27
  • 38
46

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.

Ayush Goel
  • 3,134
  • 27
  • 36
44

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.

johndpope
  • 5,035
  • 2
  • 41
  • 43
  • This was it for me, after adding CP to a very old project. – Josh Hudnall Feb 12 '14 at 23:59
  • Same for me - added CP to a very old project, could build on simulator, but as soon as I switched to build for device, the build failed. That answer helped a lot! – Florian Jul 29 '14 at 11:40
40

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

HoratioCain
  • 915
  • 9
  • 19
36

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.

Community
  • 1
  • 1
Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45
  • That was the problem for me too. I think the source of the problem was that I have upgraded CocoaPods and the format of the Podfile during the development. – gklka Aug 10 '15 at 12:52
  • 2
    I had exactly the same scenario after add target on pod. +1 for accuracy – Adriano Spadoni Oct 07 '15 at 17:24
27

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

Joachim Kurz
  • 2,875
  • 6
  • 23
  • 43
Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
  • 6
    I've run into this issue as well but I cannot seem to do these steps. I get stuck at "Add the pods static library and make sure it's at the top of the list". The static library doesn't show up with I click to add it to the Build scheme. Any idea? – Bay Phillips Dec 03 '13 at 15:51
  • @BayPhillips Close your current project and open the .xcworkspace created in your project folder. then the static library show up – junho Dec 27 '18 at 04:32
12

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

Naloiko Eugene
  • 2,453
  • 1
  • 28
  • 18
  • perfect solution for my problem :) but after removing the pods need to added it again if you want to use it – satheesh Nov 27 '15 at 00:27
11

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.

melle
  • 186
  • 2
  • 6
8

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.

i4niac
  • 1,684
  • 1
  • 17
  • 20
8

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.

Adam Sharp
  • 3,618
  • 25
  • 29
5

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

Jan M
  • 447
  • 5
  • 9
4

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

John Paul Manoza
  • 1,735
  • 25
  • 22
4

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

StackRunner
  • 1,463
  • 2
  • 16
  • 22
4

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.

cph2117
  • 2,651
  • 1
  • 28
  • 41
4

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

Build Active Architecture Only set to YES

solve my problem.

Joeful6
  • 171
  • 8
  • That helps. Thank you. Somehow it was set "YES" for Debug only while the rest configs has it "NO" and I've seen that error for all builds but Debug. – Pavel Yakimenko Oct 15 '19 at 14:23
  • This only helped me. Such answer 'Open as .workspace' is too boring. I think developers should first check install guide documents thoroughly enough.. – KoreanXcodeWorker Jan 09 '20 at 02:28
3

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.

Bhavin_m
  • 2,746
  • 3
  • 30
  • 49
2

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.
SarpErdag
  • 781
  • 1
  • 8
  • 19
  • This actually worked very well. I had updated one of the pods in my project and that broke it. I followed these steps and it worked. It was a quick fix. Thanks – agarcian Oct 06 '13 at 17:56
2

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

kernix
  • 7,970
  • 3
  • 28
  • 44
2

Nothing that was written here helped me - but it did set me on the right path. What I ended up doing was the following:

  1. Analyze the error message.

    It says Library not found: -lPods-... So it cannot find that particular library. How to resolve it? Well, make sure that this library is in the search path. So where is this library located?

  2. Search where the library is located.

    I typed find . | grep -e 'Pods-.*\.a' in a terminal in my ~/Library/Developer/Xcode/DerivedData folder. I found out my libPods-... library is located in a bunch of places, for example ~/Library/Developer/Xcode/DerivedData/[generated-name]/Build/Products/Release-iphonesimulator/libPods-[name].a

  3. Add one of these folders to the library search path

    If we add one of these folders to the library search path, then the problem will disappear. However, all the paths have a [generated-name] folder somewhere, in my case [Project]-guyraaahpczkqmhghlwgsdsqyxxs.

    So how do we add that folder to the search path responsibly? By using a build time variable! We can get a list of which variables exist by looking at this answer. It turns out one of the variables that's defined is called ${PODS_CONFIGURATION_BUILD_DIR}, and in that exact folder my libPods-[Product].a is located!

  4. Now add that folder to the library search path.

    This is the easy part, and my actual answer to this question. Go to Build Settings -> Search paths -> Library search, make sure it is collapsed, and double click on <Multiple Values>.

    In the dialog that pops up, click on the little '+' sign in the bottom left. Now type "${PODS_CONFIGURATION_BUILD_DIR}", and leave the drop-down option at "non-recursive". Type <Enter>. Now drag this entry all the way back up so that it sits directly under $(inherited).

  5. You're done. Rebuild your product!

    My error had now disappeared. Upvote this answer, close the tab, and forget the problem ever existed

Edward
  • 456
  • 3
  • 8
  • OMG I was following the same line of thought after trying so many things, found where the thing had been placed, was thinking about how to include that gibberishian folder and then I found your answer about the build time variables. Hooray. Thanks, sir. – nacmartin Aug 27 '21 at 00:14
1

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"
BabyPanda
  • 1,562
  • 12
  • 18
1

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.

ytbryan
  • 2,644
  • 31
  • 49
1

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.
rabenson
  • 9
  • 2
1

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

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.
Gagan_iOS
  • 3,638
  • 3
  • 32
  • 51
1

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

Wagner Sales
  • 1,448
  • 2
  • 10
  • 14
  • this one fixed it for me... had the problem, that the first target was building and the second target failed with "ld: library not found for -lPods..." – Muxor Nov 16 '14 at 16:08
1

If you are still getting this issue, try:

pod update

Did the work for me, hope this helps you.

Shobhit C
  • 828
  • 10
  • 15
0

try open xcworkspace file instead of xcodeproj file

Nick Hoàng
  • 417
  • 2
  • 6
0

In my case nr 4 of the FAQ in this link helped out: https://github.com/CocoaPods/CocoaPods/wiki/Creating-a-project-that-uses-CocoaPods

There are a couple of additional things you can try out if the problem persists.

user511
  • 154
  • 1
  • 7
  • I guess just throwing in a link deserves a downvote. But instead of rephrasing or copying the text from there.I found it worth mentioning however – user511 Jun 13 '13 at 09:39
  • I found it worth mentioning that there are other possible reasons for this particular error and ways to solve them. It can occur even if you open the .xcworkspace file instead of the .xcodeproj. – user511 Jun 13 '13 at 09:49
  • I don't get why you were downvoted. Your answer is perfectly valid and there are other answers here that have just copy/pasted the content you were linking :/ The link is broken tho, this is the new one http://guides.cocoapods.org/using/troubleshooting.html – josebama Apr 29 '14 at 10:18
0

renamed some_project.workspace file to some_project.workspace.backup and ran $pod install. It created a new workspace file and the error went away.

Jdizzle Foshizzle
  • 314
  • 1
  • 3
  • 18
0

I had that too, Cocoapods version 0.28.0

Easy fix here, no lengthy reading: - uninstall the Cocoapods (Command line or AppCode) - erase the Podfile, Podfile.lock, Pods folder

  • reinstall the Cocoapods
  • start the newly created workspace.
brainray
  • 12,512
  • 11
  • 67
  • 116
0

I had the same issue. It turned out to be an xCode bug in my case. All I had to do was remove the "Valid Archs", do a clean, re-add them and I was good to go. Also try updated cocoapods in general.

anders
  • 4,168
  • 2
  • 23
  • 31
0

I solved this problem with setting architectures and valid architectures same for all pods as for my project. So the hole solution in my case was:

  • update cocoa pods: sudo gem update cocoa pods
  • update pods: pod update
  • In your Pods go to to your Build settings > Architectures and set here Architectures and Valid Architectures to exact same values as in main project.
Mumbar
  • 61
  • 1
  • 3
0

To simplify @i4niac's answer:

Another common cause for this is a mismatch in the Scheme's Build Configuration. In our case, our 'AppName-AppStore' Scheme had "Release" as the Archive Build Configuration instead of "AppStore" (could be the other way around for others).

yonix
  • 11,665
  • 7
  • 34
  • 52
0

I was missing libPods.a in target, so the first thing to do is add it to linked frameworks and libraries.

Next, Product -> Build for -> Profiling (Or before adding libPods.a, if you completely missing it)

and finally check your Copy Pods resources script in Build phases (If its the same as your second target - it depends on Podfile and its targets sometimes). Then you should build successfully.

Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84
0

I ran into an issue where I had created my own .xcworkspace which kept pods form createing it's own (where is where it attaches it's library).

solution

I moved the .xcworkspace I had created, ran pod install again and then manually merged my .xcworkspace with the one pods created by openeing both workspaces and dragging files from one workspace to the other.

Community
  • 1
  • 1
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
0

Removing CocoaPods cache folders ~/Library/Caches/CocoaPods and the install pod works for me.

kaushal
  • 1,553
  • 18
  • 25
-1

I tired all the answers and in the end i was able to fix it by adding pod library into the Xcode Build scheme , after i was able to run it, tried to remove this from the build scheme and still it worked fine for me. couldn't figure out the exact reason.

sajjeel
  • 29
  • 3