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.

If you like this post and would like to receive updates from this blog, please subscribe our feed. Subscribe via RSS

6 Responses to “Undefined symbols: _SCNetworkReachabilityCreateWithName”

  1. Ian Corbin Says:

    Thanks for this. This was a huge help! Between the Reachability app examples and the Seismic XML examples, this was by far the best tutorial I could find on the topic. Thank you! Thank you! Thank you! You saved me hours of head scratching.

  2. Jason Says:

    Thanks for posting this. It’s been a big help! Thanks, Jason.

  3. SF Says:

    Thanks a ton. This filled in the gaps that I needed!

  4. Matthew Says:

    Great Post. I am still getting those two exact errors, even after I added the framework.

    any ideas?

    Thanks!

  5. silky Says:

    Quite awhile since you posted this, but wanted to say it saved me. Thanks for the post.

  6. Aayush Says:

    I had the System.configuration.framework, but I was still getting the error.
    SO I had to readd it ( dont ask me why ) and restart my xcode.
    And thats how i got it working.

Leave a Reply