What version of Go are you using (go version
)?
$ go version go version go1.20 darwin/arm64
Does this issue reproduce with the latest release?
Using MacOS with Go 1.20 error, no issue in 1.19.5
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/name/Library/Caches/go-build" GOENV="/Users/name/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/name/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/name/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.20" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hr/1lxcf_8s41dfqq139phd6twm0000gn/T/go-build1419606280=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
After compiling using gomobile bind -v -ldflags='-s -w' -target=ios -o libtest.xcframework github.com/example/test
in terminal and import the libtest.xcframework
library to xcode, it will show error in xcode when trying to compile ios app
What did you expect to see?
What did you see instead?
Undefined symbols for architecture arm64: "_res_9_nclose", referenced from: _internal/syscall/unix.libresolv_res_9_nclose_trampoline.abi0 in Libtest(go.o) "_res_9_ninit", referenced from: _internal/syscall/unix.libresolv_res_9_ninit_trampoline.abi0 in Libtest(go.o) "_res_9_nsearch", referenced from: _internal/syscall/unix.libresolv_res_9_nsearch_trampoline.abi0 in Libtest(go.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Related: https://github.com/golang/go/issues/58159
Comment From: bcmills
(attn @golang/ios)
Comment From: bcmills
import the library to xcode
Import how? (Is there something you need to configure in xcode to set the linker flags for the final executable?)
Comment From: xDragonZ
Import xcframework to xcode project target. No, nothing to configure in xcode
Comment From: bcmills
@xDragonZ, try adding libresolv.9.tbd
and/or libresolv.tbd
in the Linked Frameworks and Libraries
section.
(See https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-06-rust-on-ios.html.)
Comment From: xDragonZ
Thank you 🫡 finally got it working.
Passing extldflags=-lresolv
to gomobile doesn't works but adding libresolv.tbd
able to compile the ios app without error now.
Comment From: bcmills
Great! Want to send a CL to update the documentation? (Probably goes in one of the files in https://cs.opensource.google/go/x/mobile/+/master:cmd/gomobile/ ..?)
Comment From: gurupras
Could you please share how you got this working? Running into the same issue and somehow adding libresolv.tbd and libresolv.9.tbd (for me it shows under Apple SDK and not IOS SDK; not sure if that matters) does nothing.
Comment From: xDragonZ
@gurupras you need to add it to "Frameworks & Libraries" section too
Comment From: drew-512
Hi friends,
Not clear if downstream now has to deal with this from now on, or if this will be addressed upstream (making many gophers happy).
Comment From: tmm1
Adding to Frameworks & Libraries wasn't working for me. I had to go to Build Phases > Link Libraries and add it there
Comment From: yulianaboglione
Hola puedes dejar lo Pasos que hiciste plis??? Tengo el mismo problema y no entiendo bien lo qué hay que hacer por favor necesito saber qué fue lo que hizo
Comment From: dreacot
include -tags=netgo
while compiling
e.g
gomobile bind -v -tags=netgo -ldflags='-s -w' -target=ios -o libtest.xcframework
Comment From: notatestuser
Unfortunately, the suggested fix to use -tags=netgo
appears to cause DNS resolution issues on real iOS devices running iOS 17+. It seems that Apple is preventing DNS resolvers embedded by apps to work properly.
Comment From: newswangerd
Unfortunately, the suggested fix to use
-tags=netgo
appears to cause DNS resolution issues on real iOS devices running iOS 17+. It seems that Apple is preventing DNS resolvers embedded by apps to work properly.
If anyone else is running into the DNS resolution issue, I found a fix for it here: https://github.com/ipfs-shipyard/gomobile-ipfs/issues/19
I copied the fix linked to that ticket by adding this to the entrypoint for my library to set the system wide resolver.
var dialer net.Dialer
net.DefaultResolver = &net.Resolver{
PreferGo: false,
Dial: func(context context.Context, _, _ string) (net.Conn, error) {
conn, err := dialer.DialContext(context, "udp", "84.200.69.80:53")
if err != nil {
return nil, err
}
return conn, nil
},
}
This worked but I don't know why or how. It looks like it's hard coding a specific DNS server, which I'm not a fan of. I'm going to do some more experimenting to see if I can find a better workaround, but I'll leave this here in case anyone else runs into the same problem.
Comment From: newswangerd
I finally figured out why it wasn't working for me to link libresolve like others were saying. I'm using flutter and I had to go link it from my pods, rather than the main app. That allowed me to remove the net.Dialer solution