How to Fix Xcode Build Error: “library not found for -lCocoaAsyncSocket”

hipster' Santos
3 min readJul 17, 2024

Encountering build issues in Xcode can be a common and frustrating experience. One such issue is the “library not found for -lCocoaAsyncSocket” error. This article will walk you through understanding and resolving this error step-by-step.

Example Issue: Build Error in Xcode

Here’s an example of the error you might encounter:

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

Understanding the Issue

The error ld: library not found for -lCocoaAsyncSocket indicates that the linker is unable to find the CocoaAsyncSocket library, which is required by your project. This can happen for several reasons, including:

  1. The library is not installed.
  2. The library path is not correctly set in the project settings.
  3. The project dependencies are not properly configured.

Step-by-Step Solution

1. Verify Library Installation

First, ensure that the CocoaAsyncSocket library is installed in your project. This is typically done using CocoaPods.

Steps to Fix:

  • Open the Podfile in your project's root directory.
  • Ensure that CocoaAsyncSocket is listed as a dependency. Your Podfile should include:
pod 'CocoaAsyncSocket'

Save the Podfile and run the following command in the terminal to install the dependencies:

Your podfile should looks like this below

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!

flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
use_frameworks! :linkage => linkage.to_sym
end

target 'test1' do
config = use_native_modules!

use_react_native!(
:path => config[:reactNativePath],
:flipper_configuration => flipper_config,
:app_path => "#{Pod::Config.instance.installation_root}/.."
)

pod 'CocoaAsyncSocket' # Add this line here is the line you need

target 'test1Tests' do
inherit! :complete
# Pods for testing
end

post_install do |installer|
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false
)
end
end

now run the installation of dependency by running

pod install

2. Update Xcode Project Settings

Ensure that Xcode is correctly configured to link against the CocoaAsyncSocket library.

Steps to Fix:

  1. Open your .xcworkspace file (not the .xcodeproj file) in Xcode.
  2. Select your project in the Project Navigator.
  3. Navigate to the Build Settings tab.
  4. Under the Search Paths section, verify that Library Search Paths includes the path to the CocoaAsyncSocket library. Typically, this should include $(inherited) and $(PROJECT_DIR)/Pods/**.
  5. Ensure that the Other Linker Flags setting includes -lCocoaAsyncSocket.

3. Clean and Rebuild the Project

After verifying the installation and settings, clean and rebuild your project to ensure that the changes take effect.

Steps to Fix:

  1. In Xcode, go to the Product menu and select Clean Build Folder.
  2. Rebuild the project by selecting Product > Build.

Verifying the Fix

After applying these fixes, it’s important to verify that the issue is resolved.

  1. Clean the Project: In Xcode, go to the Product menu and select Clean Build Folder.
  2. Rebuild the Project: Build the project again by selecting Product > Build.
  3. Check for Errors: Ensure that the linker error related to CocoaAsyncSocket is resolved and that there are no other related errors or warnings.

--

--

hipster' Santos
hipster' Santos

Written by hipster' Santos

Fullstack developer , Distributed system engineer,Competitive programmer find at https://github.com/HipsterSantos

No responses yet