162

I am getting an error after I put my application in an AdMob. The app was working until today. The error is the following:

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

How can I fix this? Thank you.

3

25 Answers 25

358

I had a similar "library not found" issue. However it was because I accidentally was using the .xcodeproj file instead of the .xcworkspace file.

8
  • 5
    Can somebody please explain the purpose of .xcodeproj and .xcworkspace?
    – EFreak
    Jul 10, 2018 at 9:34
  • 22
    Things like this make me love the Javascript ecosystem
    – Mark
    Jul 10, 2018 at 23:46
  • 8
    xcworkspace is when you use Cocoapods. It's not Xcode problem, but the users.
    – Azam
    Jan 17, 2019 at 4:07
  • 2
    ffs I wasted a good 5 hours earlier this afternoon because I didn't realize the difference. -_-
    – Will
    Jul 17, 2019 at 0:46
  • 3
    .xcworkspace is when you have more than 1 "project" inside your solution. For example you can have external libraries (cocoapods) or your own library that you use in many projects. Oct 28, 2019 at 15:22
120

Sometimes you just remove the reference of the library and add reference again.

Apart from adding the Google Mobile Ads SDK and other libraries again from scratch, I would recommend you checking the Library Search Paths. There are instances when you copy or duplicate a target, Xcode decides that it needs to escape any double quotes " with a '\'. Make sure you remove all the \’s - it should look like this -

enter image description here

I was able to duplicate the error, by doing prefixing my path with multiple '\'.

5
  • good one, after pod install, one of the library was not listed there. I don't know why but adding that library path makes it work. Apr 2, 2018 at 11:02
  • Well this fixed my issue "Library not found for -lART" and it's really unbelievable ! Thank you !
    – ZedTuX
    May 13, 2019 at 8:05
  • 1
    Consider "Header Search Paths" too. Aug 14, 2019 at 9:51
  • @raurora How do you access library search paths?
    – MathMax
    Jun 15, 2020 at 15:20
  • 1
    @MassimoFrittelli Project > Build Settings tabs > Search Paths. You can type on the search option too.
    – raurora
    Jun 16, 2020 at 5:16
97

Select your Target, go to "Build Phases" in "Link Binary With Libraries" remove ".a" file of that library. Clean and Build.

2
  • 3
    Yup, strange enough that Xcode doesn't mark it missing by coloring it red
    – brainray
    May 15, 2017 at 11:49
  • Really nice!! my problem was when I added user framework to old project. Remove coreplot.a and works fine!!!! Jul 20, 2018 at 8:12
68

If error related to Cocoapods as follow:

library not found for -lPod-...

You need to check Other Linker Flags and remove it from there.

Extra Information: If you have an old project that uses cocoapods. And recently you needed to add the use_frameworks! to your podfile. cocoapods will not add the libraries to your Other Linker Flags anymore cause its inherited. Therefore, you may need to remove those manually from the other linker flags which they were added before using the use_frameworks!

8
  • 1
    I have many flags here, should I remove all or just the one for the Pod? Mar 20, 2016 at 14:08
  • If those flags causes a problem. you should remove them or keep them and add the library if you still want to use it.
    – hasan
    Mar 20, 2016 at 14:11
  • 1
    I guess that happens when you try to remove the library that is added by cocoa pods manually. The correct way is to remove the library from your podfile. then you run pod install again
    – hasan
    Dec 14, 2016 at 10:27
  • 1
    Thanks!! This was a clue for me :). In my case, the duplicate target has divided every -l"framework" in two lines "-l" and "framework" !! Mar 14, 2017 at 13:09
  • 1
    @IanSteffy just combine it Apr 12, 2018 at 13:29
60

For my case Xcode 7, also worked in Xcode 9.1/9.2

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

set Build Active architecture Only to Yes

enter image description here

4
  • 2
    What about when we need to create a Production build for App Store? I mean it should be NO for Production Build.
    – Jabbar
    Jul 27, 2016 at 12:05
  • agree it should be NO for production
    – Ted
    Jul 27, 2016 at 13:09
  • 2
    Will this NO effect on Production Build Installation?
    – Jabbar
    Jul 27, 2016 at 13:42
  • 1
    Worked for me while integrating Pinterest SDK on XCode 9.2 and iOS 11. Dec 18, 2017 at 11:21
15

If error is like following

ld: library not found for -lpods

I found that a file "libPods.a" which is in red colour(like missing files) was created somehow in the Framework group of the project. I just simply removed that file and everything got fine.

EDIT: Another Solution

Another Solution that I have already answered in the similar question is in this link

0
13

goto Build Phases -> Link Binary With Libraries and remove library which show errors because that library is not available in project folder

1
  • This fixed my particular problem. I had two similar named libraries, one named libPods-Foo BarTests.a and another one named libPods-FooBarTests.a .
    – edenwaith
    Mar 16, 2018 at 19:29
7

Late for the answer but here are the list of things which I tried.So it will be in one place if anyone wants to try to fix the issue.

  1. Valid architecture = armv7 armv7s
  2. Build Active Architecture only = NO
  3. Target -> Build Settings ->Other Linker Flags = $(inherited)
  4. Target -> Build Settings ->Library Search Path = $(inherited)
  5. Product Clean
  6. Pod Update in terminal
4

ld: library not found for

It is compile time error for a Static Library that is caused by Static Linker

ld: library not found for -l<Library_name>

1.You can get the error Library not found for when you have not include a library path to the Library Search Paths(LIBRARY_SEARCH_PATHS)

ld means Static Linker which can not find a location of the library. As a developer you should help the linker and point the Library Search Paths

Build Settings -> Search Paths -> Library Search Paths 

2.Also you can get this error if you first time open a new project (.xcodeproj) with Cocoapods support, run pod update. To fix it just close this project and open created a workspace instead (.xcworkspace )

[Vocabulary]

3

As for me this problem occurs because i installed Material Library for IOS. to solve this issue

1: Go to Build Settings of your target app.

2: Search for Other linker flags

3: Open the other linker flags and check for the library which is mention in the error.

4: remove that flag.

5: Clean and build.

I hope this fix your issue.

2

In my case there was a naming issue. My library was called ios-admob-mm-adapter.a, but Xcode expected, that the name should start with prefix lib. I've just renamed my lib to libios-admob-mm-adapter.a and fixed the issue.

I use Cocoapods, and it links libraries with Other linker flags option in build settings of my target. The flag looks like -l"ios-admob-mm-adapter"

Hope it helps someone else

2

Simply, GoogleAdMobAds.a is missing in project target. For me it was libAdIdAccessLibrary.a Please check attached screenshot

enter image description here

2

In the case of ld: library not found for -{LIBRARY_NAME} happened because the library file(s) is not existing.

Check the library path on your application targets’ “Build Phases” Library Search Paths tab.

The library file(s) path must be according to the real path for example if your file(s) in the root of the project you must set the path like $(PROJECT_DIR)

1
  • This happened to me when I updated a pod project to XCode 13 relating to the Nimble framework that the previous version Cocoapod tool (used to create the workspace) stuck into the Podfile at a specific version. This made pod update not fix it right away, I had to replace pod 'Nimble', '~> X.Y.Z' with just pod 'Nimble' which updated Nimble to the latest version which solved my problem.
    – Papyrus
    Feb 4, 2022 at 1:24
1

I know this is a bit old, but I just hit a similar issue and running 'pod update' fixed this for me. My library error was with AFNetworking...

Just be careful doing pod update if you don't use explicit versions in your pod file.

1

This error is very weird.

I had this error with -ldAfnetworking and I only copy my project in other path and works.

1

I tried renaming my build configuration Release to Production, but apparently cocoa pods doesn't like it. I renamed it again to Release, and everything builds just fine.

1
  • you also could have rename the target in the podfile. Jun 7, 2017 at 8:17
1

@raurora's answer pointed me in the right direction. I was including libraries in my "watchkitapp Extension/lib" path. In this case, the Library Search Path needed to be escaped with a '\', but the linker didn't seem to understand this. To fix / work-around the issue, I moved my lib path up one level so it was no longer in a directory that contained a space in the name.

1

I just update the pod file 'pod update' and it start to work for me normally.

1

Running 'pod update' in my project fixed my problem with the 'library not found for -lSTPopup' error.

Remarking Trevor Panhorst's answer:

"Just be careful doing pod update if you don't use explicit versions in your pod file."

1

Easy solution. Here's how I'd fix the issue:

  1. Go to the directory platforms/ios
  2. Then, execute the command pod install

That's it. This should install the missing library.

1
  1. Cleaned Build Folder
  2. Restarted XCode

Went away...

0

I was getting similar bugs on library not found. Ultimately this is how I was able to resolve it

  1. Before starting with Xcode Archive, used flutter build iOS
  2. Changed the IOS Deployment Target to a higher target iOS 11.2 . Earlier I had something like 8.0 which was giving all the above errors.
  3. Made sure that the IOS deployment targets in Xcode are same in the Project, Target and Pods
0

I was also facing the same issue and spent more than 24 hours to solve this, I tried everything from the above solutions but what finally works for me is

  1. Build settings -> Select Target
  2. Basics
  3. User-defined
  4. Change the VALID_ARCHS to arm64
0

Dude you need a reinstallation.

  1. Delete simply "rm -rf" pods.
  2. Install Pods "bundle exec pod install"

Works well then.

-1

the same here, but in my case was resolved with answer the kenorb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.