Skip to content →

Undefined symbols: _SCNetworkReachabilityCreateWithName

I was recently adding some code to check for the availability of the network, so I can display an error to the user if unavailable.

I looked at the SeismicXML application and borrowed the following code:

// Use the SystemConfiguration framework to determine if the host that provides
// the RSS feed is available.
- (BOOL)isDataSourceAvailable
{
    static BOOL checkNetwork = YES;
    if (checkNetwork) { 
// Since checking the reachability of a host can be expensive, 
// cache the result and perform the reachability check once.
        checkNetwork = NO;
        
        Boolean success;    
        const char *host_name = "earthquake.usgs.gov";
		//const char *host_name = "localhost";

        SCNetworkReachabilityRef reachability =
SCNetworkReachabilityCreateWithName(NULL, host_name);
        SCNetworkReachabilityFlags flags;
        success = SCNetworkReachabilityGetFlags(reachability, &flags);
        _isDataSourceAvailable = success && 
(flags & kSCNetworkFlagsReachable) && 
!(flags & kSCNetworkFlagsConnectionRequired);
        CFRelease(reachability);
    }
    return _isDataSourceAvailable;
}

I wouldn’t compile unless I added the following import:

#import <SystemConfiguration/SystemConfiguration.h> 

After adding this I still go 2 more errors, but these were a bit more cryptic.

 Undefined symbols:
"_SCNetworkReachabilityCreateWithName", referenced from:
-[TheElementsAppDelegate isDataSourceAvailable] in TheElementsAppDelegate.o
"_SCNetworkReachabilityGetFlags", referenced from:
-[TheElementsAppDelegate isDataSourceAvailable] in TheElementsAppDelegate.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

After some digging around I realized that I was missing the SystemConfiguration.framework framework.

So here is what I did to add it.
1. I right click on “Frameworks” and choose: Add < Existing Framework
add_framework

2. Browsed to the file: /System/Library/Frameworks/SystemConfiguration.framework

3. Rebuilt the project and my error was gone.

Published in Code iOS