Symbol not found: ___res_9_state

When running my app with Xcode16.4, it crashed with the error:

dyld[1045]: Symbol not found: ___res_9_state

Referenced from: <8B329554-5BEF-38D0-BFCD-1731FA6120CB> /private/var/containers/Bundle/Application/00C941BA-E397-4D0B-B280-E75583FF2890/***.app/***.debug.dylib

Expected in: <7D74C679-8F55-3A01-9AA2-C205A4A19D3E> /usr/lib/libresolv.9.dylib

The ___res_9_state related code in my app is:

let state = __res_9_state()
res_9_ninit(state)
var servers = [res_9_sockaddr_union](repeating: res_9_sockaddr_union(), count: Int(MAXNS))
let found = Int(res_9_getservers(state, &servers, Int32(MAXNS)))
res_9_nclose(state)
if found > 0 {
    return Array(servers[0..<found]).filter() { $0.sin.sin_len > 0 }
} else {
    return []
}

Previously, __res_9_state() could run normally in Xcode 16.1

How to fix this problem?

If you compare the header files for resolv.h included with the SDKs for Xcode 16.1 and Xcode 16.4, you'll see there's quite a signifiant difference. This is also visible in the Apple open source repository. In particular, note how this YYYYMMDD formatted macro in resolv.h jumped from this in Xcode 16.1:

#define	__RES	19991006

to this in Xcode 16.4:

#define	__RES	20090302

You should take a look at your overall code to make sure that it is compatible with those changes you can see by diffing the header files.

— Ed Ford,  DTS Engineer

As my colleague Ed mentioned, the <resolv.h> interface has a lot of ‘interesting’ backstory. My general advice is to avoid that API wherever possible. However, before we dig into alternatives I want to ask about this:

When running my app with Xcode16.4, it crashed with the error:

I built a tiny test function that calls __res_9_state and called it from both a macOS program and an iOS app and both worked just fine. So where are you running your code? Specifically, what platform and what version of that platform?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Symbol not found: ___res_9_state
 
 
Q