go: x/mobile: Getting undefined reference while generating binding using gomobile
What version of Go are you using (go version)?
$ go version: go1.12.4 linux/amd64
What operating system and processor architecture are you using (go env)?
go env Output
$ go envGOARCH=“amd64” GOBIN=“/usr/local/go” GOCACHE=“/home/–/.cache/go-build” GOEXE=“” GOFLAGS=“” GOHOSTARCH=“amd64” GOHOSTOS=“linux” GOOS=“linux” GOPATH=“My Go path” GOPROXY=“” GORACE=“” GOROOT=“/usr/local/go” GOTMPDIR=“” GOTOOLDIR=“/usr/local/go/pkg/tool/linux_amd64” GCCGO=“gccgo” CC=“gcc” CXX=“g++” CGO_ENABLED=“1” GOMOD=“” CGO_CFLAGS=“-g -O2” CGO_CPPFLAGS=“” CGO_CXXFLAGS=“-g -O2” CGO_FFLAGS=“-g -O2” CGO_LDFLAGS=“-g -O2” PKG_CONFIG=“pkg-config” GOGCCFLAGS=“-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build242944229=/tmp/go-build -gno-record-gcc-switches”
What did you do?
-
I have go package, I am trying to generate go binding for that using gomobile tool. (a) gomobile bind -o my.aar -target=android mygopackage
-
Details about my go package [mygopackage]: (a) $ tree ├── file.go └── res.c
(b) Details about file.go:
(i) I am including my res.c
(ii) I am just redirecting my function call to c file.© Details about my res.c file: (i) I am including one header for getting interfaces: #include <ifaddrs.h> : http://man7.org/linux/man-pages/man3/getifaddrs.3.html and I am calling one API: getifaddrs()
Issue: While generating the go mobile binding it is giving undefined reference : $ gomobile bind -o my.aar -target=android mygopackage
gomobile: go build -buildmode=c-shared -o=/tmp/gomobile-work-063445150/android/src/main/jniLibs/armeabi-v7a/libgojni.so gobind failed: exit status 2 ‘#mygopackage’ src/mygopackage/res.c:15: error: undefined reference to ‘getifaddrs’ clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have browsed all issues but no issue is related to this.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (10 by maintainers)
Commits related to this issue
- cmd/gomobile: add arg to set android api level Fixes golang/go#31905 Change-Id: Icee0ece2e78028fa4afd8b273b86e4eed404d99a Reviewed-on: https://go-review.googlesource.com/c/mobile/+/176077 Reviewed-b... — committed to imWildCat/go-mobile by AlexRouSg 5 years ago
- cmd/gomobile: add arg to set android api level Fixes golang/go#31905 Change-Id: Icee0ece2e78028fa4afd8b273b86e4eed404d99a Reviewed-on: https://go-review.googlesource.com/c/mobile/+/176077 Reviewed-b... — committed to imWildCat/go-mobile by AlexRouSg 5 years ago
Change https://golang.org/cl/176077 mentions this issue:
cmd/gomobile: add arg to set android api level