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 env

GOARCH=“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?

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

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

Most upvoted comments

Change https://golang.org/cl/176077 mentions this issue: cmd/gomobile: add arg to set android api level