x/mobile: Getting undefined reference while generating binding using gomobile #31905
Comments
Hello @eliasnaur |
As per my analysis this symbol is present in "libc" library. But I am not sure how gomobile internally links "libc" while we run gomobile tool to generate .aar file. |
According to a quick Google search, getifaddrs is not available before Android API level 24. Gomobile builds with a lower API level (21 if I remember correctly). You should be able to work around the issue while maintaining Android compatibility by using dlopen and dlsym to access getifaddrs. |
@eliasnaur is there anything preventing android from having a command line arg to set the API level? I saw IOS has one and find it weird android doesn't. |
Nothing other than no-one has implemented it yet.
|
@eliasnaur , |
@jay11ca39 if you want to implement it, look at https://github.com/golang/mobile/blob/master/cmd/gomobile/env.go#L311 and https://github.com/golang/mobile/blob/master/cmd/gomobile/build.go#L220 |
@eliasnaur , Then, it means it is taking minimum API level as 15. But, Then I tried to include some symbols that is introduced in Android API level: 8 But, it is also giving the undefined reference error: As per this testing I got confused that reported issue is related to minimum API level or something else. Can you please provide your opinion on this. |
The uses-sdk declaration is for Java code. A #cgo CFLAGS -D__ANDROID_API__=24 in your .c file. |
Tried to place in .c file but it did not help. @eliasnaur , I assume minimum API level in gomobile is at least more than 8. |
@jay11ca39 Can you link to docs showing |
@AlexRouSg , @eliasnaur , |
"it" referring to the api version command line arg. |
@jay11ca39 what is that last comment suppose to mean? You asked how to get gomobile to use a different API level and I told you where to start looking. |
Change https://golang.org/cl/176077 mentions this issue: |
Hello @eliasnaur
I did not find steps to build gomobile code from source code. Can you, let me know how to to build from source ? |
#31905 (comment) |
Anything you can obtain with Please see https://golang.org/doc/code.html#remote But the changes have been merged, this means you can |
You should be able to just run go install |
Thanks @eliasnaur , @AlexRouSg for all your help and suggestions. I am able to build my code using -androidapi command line flag introduced in: https://go-review.googlesource.com/c/mobile/+/176077 |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat 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.
(c) 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
I have browsed all issues but no issue is related to this.
The text was updated successfully, but these errors were encountered: