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: ndk-build finds wrong library path for dlopen #17807

ab-smith opened this issue Nov 5, 2016 · 5 comments

x/mobile: ndk-build finds wrong library path for dlopen #17807

ab-smith opened this issue Nov 5, 2016 · 5 comments
mobile NeedsInvestigation


Copy link

@ab-smith ab-smith commented Nov 5, 2016

Based on the Android NDK samples ( 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

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"


On the gomobile example directory, create an Android binding library :
cd $GOPATH/src/
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/" 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/" not found

When I check the symbols on the intermediate library ( I see that the 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)


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

I can make it work by patching the and fixing the path binary, but this is not a solution.

@quentinmit quentinmit changed the title Gomobile/ndk-build wrong library path for dlopen x/mobile: ndk-build finds wrong library path for dlopen Nov 7, 2016
@quentinmit quentinmit added this to the Unreleased milestone Nov 7, 2016
@quentinmit quentinmit added the NeedsInvestigation label Nov 7, 2016
Copy link

@7d4b9 7d4b9 commented Nov 11, 2016

The issue here is that gomobile does not set a library SONAME at the linker step for building If this attribute remain unset the further linking to that library, in your example for, will conduce to hardcode internally the current build tree path of your which will no more be available after a deployment on targeted.

To solve the issue you must instruct the linker to set the SONAME value of
Since gomobile uses external linkers to achieve the final .aar package the parameter can be provided as following:

gomobile bind -target android -ldflags=-extldflags=-Wl,-soname,

You can have a look here for more information about shared library workflow.

Copy link

@ab-smith ab-smith commented Nov 11, 2016

Ok thanks

Copy link

@smoothdvd smoothdvd commented Mar 8, 2019

@7d4b9 Save my life!

Copy link

@tmm1 tmm1 commented Mar 30, 2019

@eliasnaur should this be the default behavior in gomobile?

Copy link

@jerson jerson commented Apr 1, 2021

@7d4b9 thank you so much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
mobile NeedsInvestigation
None yet

No branches or pull requests

7 participants