Fix: `library not found for -lGoogleAdMobAds` in Xcode

Fix: `library not found for -lGoogleAdMobAds` in Xcode

Written by

in

Quick answer: If your app uses CocoaPods, open the generated .xcworkspace file—not the .xcodeproj—and build again. If the error remains, inspect the app target’s linker flags and library search paths for a stale GoogleAdMobAds reference or an invalid path.

Why this happens

The linker error ld: library not found for -lGoogleAdMobAds means Xcode was instructed to link a library named GoogleAdMobAds, but could not find a matching library in the locations it searched. The -l flag requests a library by name; it is not a check that the Google Mobile Ads SDK is installed or configured correctly.

A common cause is opening the app’s .xcodeproj directly when CocoaPods has integrated dependencies into a .xcworkspace. The workspace brings the app project and the Pods project together. Building only the project can leave Xcode without the dependency configuration it needs.

Another possibility is a stale manual linker entry. A target may still request the old GoogleAdMobAds library after the project’s SDK setup changed. A bad Library Search Paths entry can also prevent Xcode from finding a library that is present. These settings can differ by target and build configuration, so a project that worked before may fail after a target was copied or edited.

How to fix it

1. Open the CocoaPods workspace

If this app uses CocoaPods, first check the project folder for a file named after your project with the .xcworkspace extension. Open that file in Xcode and build the app target from the workspace.

For example, if the project contains MyApp.xcodeproj and MyApp.xcworkspace, open MyApp.xcworkspace. Avoid reopening the .xcodeproj from Finder or a recent-project list while troubleshooting; doing so can put you back in the project without its Pods integration.

If there is no workspace, confirm that CocoaPods is actually part of this project before assuming this is the cause. A project managed with Swift Package Manager or manually added frameworks will have a different dependency setup.

2. Remove a stale GoogleAdMobAds linker entry

In the workspace, select the app project in the navigator, then select the app target. Check the target’s Build Phases and Build Settings for a manually added library reference.

In Build Phases, inspect Link Binary With Libraries. If it contains a missing GoogleAdMobAds item, remove that reference only if the current SDK integration does not provide or require it. Also check Other Linker Flags in Build Settings for an old -lGoogleAdMobAds entry. Remove a stale flag rather than adding a new search path for a library that is no longer part of the project.

The name in this error is a clue: it may come from an older manual integration, while the app’s current Google Mobile Ads dependency may be configured differently. Use the installation method and product supplied by the SDK version your project actually uses. Do not download an arbitrary library file to satisfy the linker.

After changing a setting, check both Debug and Release if the error occurs in only one configuration. Also check whether the setting is defined at the project level, target level, or in an .xcconfig file; a value in one place can be overridden or supplemented elsewhere.

3. Check Library Search Paths for invalid entries

In the app target’s Build Settings, search for Library Search Paths. These entries must point to directories where Xcode can search for linkable libraries. They are not library names: putting GoogleAdMobAds in this setting does not provide the missing library.

Look for a path that no longer exists, points to a different checkout location, or contains unintended backslashes. When a path was copied or a target duplicated, an incorrectly escaped character can make the entry point somewhere other than the intended directory. Correct or remove the bad entry; do not remove valid inherited settings merely to silence the error.

If a path includes spaces, preserve it as a single path entry using Xcode’s normal build-setting formatting. Compare it with the actual folder on disk and with the corresponding setting in a working target, if you have one. Remember that the app target and any extension target can have separate search paths.

4. Refresh CocoaPods integration when the workspace or Pods setup is out of date

If the project uses CocoaPods, run pod install from the directory containing the Podfile:

pod install

Then open the generated workspace and build again. pod install installs dependencies according to the existing Podfile and lockfile; it is a better first repair step than changing dependency versions with pod update when the problem is just a broken local integration.

If the Podfile does not declare the Google Mobile Ads dependency, or the dependency was removed while old linker flags remain, align the project settings with the current Podfile and SDK setup. Do not manually add a guessed -l flag. If you use Swift Package Manager instead, resolve the package in Xcode and remove obsolete CocoaPods or manual-linker configuration only after confirming it is no longer needed.

5. Rebuild and verify the failing target

Build the same scheme, target, and configuration that produced the error. If an app extension or another target has its own Google Mobile Ads reference, fixing only the main app target will not fix that target’s build.

If the error continues, inspect the build log for the exact linker invocation and identify where -lGoogleAdMobAds is being added. Search the project’s build settings and configuration files for that literal flag. Remove or correct its source, then build again. This is more reliable than repeatedly cleaning Derived Data when the underlying linker instruction is still present.

How to prevent it

  • Open the .xcworkspace for CocoaPods projects, not the .xcodeproj.
  • Prefer the dependency manager’s integration over manually adding SDK libraries and linker flags.
  • After copying a target, review its linker flags and search paths; they may not match the original target.
  • Keep Debug and Release settings consistent unless they intentionally differ.
  • Avoid adding a search path or downloading a library until you have confirmed the SDK version and integration method require it.

FAQ

What does -lGoogleAdMobAds mean?

It tells the linker to look for a library with the name GoogleAdMobAds. The error means the linker could not find that library in the paths available to the target; it does not, by itself, identify why it is missing.

Should I add GoogleAdMobAds to Library Search Paths?

No. Library Search Paths contains directories, not library names. First check whether the project is using the correct workspace and whether the target has an obsolete linker flag or a broken path.

Will cleaning the build folder fix this error?

It may help with stale build artifacts, but it will not fix a linker flag that still requests a missing library or an invalid search path. Correct the project or dependency configuration first.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.