Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: Undefined symbols _res_9_nclose with Go 1.20 #58416

Open
xDragonZ opened this issue Feb 8, 2023 · 9 comments
Open

x/mobile: Undefined symbols _res_9_nclose with Go 1.20 #58416

xDragonZ opened this issue Feb 8, 2023 · 9 comments
Labels
Documentation help wanted mobile Android, iOS, and x/mobile NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Milestone

Comments

@xDragonZ
Copy link

xDragonZ commented Feb 8, 2023

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: #58159

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Feb 8, 2023
@gopherbot gopherbot added this to the Unreleased milestone Feb 8, 2023
@bcmills
Copy link
Member

bcmills commented Feb 8, 2023

(attn @golang/ios)

@bcmills
Copy link
Member

bcmills commented Feb 8, 2023

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?)

@xDragonZ
Copy link
Author

xDragonZ commented Feb 8, 2023

Import xcframework to xcode project target. No, nothing to configure in xcode

@bcmills
Copy link
Member

bcmills commented Feb 9, 2023

@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.)

@xDragonZ
Copy link
Author

xDragonZ commented Feb 9, 2023

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.

@bcmills
Copy link
Member

bcmills commented Feb 9, 2023

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/ ..?)

@bcmills bcmills added Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Feb 9, 2023
@gurupras
Copy link

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.

@xDragonZ
Copy link
Author

@gurupras you need to add it to "Frameworks & Libraries" section too

@drew-512
Copy link

drew-512 commented Mar 16, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation help wanted mobile Android, iOS, and x/mobile NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin
Projects
None yet
Development

No branches or pull requests

5 participants