-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: ndk-build finds wrong library path for dlopen #17807
Comments
The issue here is that gomobile does not set a library SONAME at the linker step for building To solve the issue you must instruct the linker to set the SONAME value of
You can have a look here for more information about shared library workflow. |
Ok thanks |
@7d4b9 Save my life! |
@eliasnaur should this be the default behavior in gomobile? |
@7d4b9 thank you so much!! |
@7d4b9 this fxxking saved my life when I am trying to build a go-based |
Hi,
Based on the Android NDK samples (https://github.com/googlesamples/android-ndk/tree/master) and mainly the hello-libs, I'm trying to call a prebuilt library.
In fact, it is pretty simple for a C-based library (using the examples), but when my .so is built using Go, the ndk-build linker seems to go crazy and uses an intermediate path to reference the .so library which causes the app crash.
Go versions
go version go1.7.1 darwin/amd64
gomobile version +6ecf8ee Sun Oct 16 10:25:40 2016
Go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/dev/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b_/y2nd3vgn4m1929dg56thjdn40000gn/T/go-build047047925=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Steps
On the gomobile example directory, create an Android binding library :
cd $GOPATH/src/golang.org/x/mobile/example/bind/hello
gomobile bind -target android
extract the so library from the resulting aar.
create a simple .h header to reference the symbol (Java_go_hello_Hello_Greetings)
add the result to the sample project (the same thing as gperf)
without even referencing the function on the main cpp, build the project (gradle build) --> build successful
install the resulting apk
What did you expect to see?
a working app
What did you see instead?
java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/me/Desktop/vm-win/ndk-build-golang/hello-libs-2/app/src/main/cpp/../../../../distribution/libgo/lib/arm64-v8a/libgojni.so" not found
after decomposing the code and focusing only on the library build (basic ndk project) I still get the same thing :
java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/me/dev/android-ndk/hello-libs/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libgojni.so" not found
When I check the symbols on the intermediate library (libhello-libs.so) I see that the libgojni.so is referenced with a full path instead of just the filename (which is the case of a C-based library)
(both libraries are at the same level when I extract the apk)
Thanks,
additional info
A C-based library is working but not the Go-based one. Maybe the latter is missing something ?
I've uploaded a buildable project to https://github.com/ab-smith/ndk-build-golang
I can make it work by patching the libhello-libs.so and fixing the path binary, but this is not a solution.
The text was updated successfully, but these errors were encountered: