How to Fix “ld: library not found for” in macOS Xcode

The error “ld: library not found for -lXXX” appears when running an Xcode project, indicating that the linker can’t locate a static library your project relies on.

You may see at least one of the following:

ld: library not found for -lsystem

ld: library not found for -lssl

ld: library not found for -lgfortran

Here’s what you need to do.

#1 Add the Missing Library to Your Project

Locate the missing library and add it directly to your Xcode project. This ensures that the necessary files are included, avoiding linker issues.

#2 Update “Library Search Paths” Build Setting

Navigate to your Xcode project settings and adjust the “Library Search Paths” build setting. Include the directory where the missing library is stored, helping the linker find it during the build process.

#3 Revise “LD_LIBRARY_PATH” Environment Variable

Update the “LD_LIBRARY_PATH” environment variable to include the path of the static library. This guides the linker to the correct location during the build, resolving the library not found error.

#4 Specify a Path

Consider adding the path -L/Library/Developer/CommandLineTools/usr/lib/swift_static/macosx/ as an extra measure. This can be particularly helpful based on community feedback.

Some have successfully used -L/opt/local/lib to resolve similar linker issues on macOS.

Leave a Comment

Cydia Geeks