Discussion:
"dlopen link_image[1995]: failed to link" in froyo
(too old to reply)
fycd
2010-12-02 13:03:46 UTC
Permalink
in froyo. I made two lib: libdl1.so and libdl2.so.
libdl1.so load libdl2.so by dlopen();

and i wrote an executable file "Loadlibfile" witch to test the
libdl2.so

also. I wrote an apk "myApk" to load libdl1.so by System.loadLibrary()

I push the Loadlibfile into /data/data/com.myApk/lib/ (libdl1.so and
libdl2.so are there, too),
and execute ./Loadlibfile. It load libdl2.so well.

but when i run myApk in emulator ,it shows error: "dlopen
link_image[1995]: failed to link 'libdl2.so'" ==>
(load by dlopen("/data/data/com.myApk/lib/libdl2.so") ).
and
" find_library[1188]: 37 'libdl2.so' failed to load previously" ==>
(load by dlopen("./libdl2.so") or dlopen("libdl2.so") )


Please some one help fix it. it has troubled me for a week's long...
T_T
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-***@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
David Turner
2010-12-02 15:19:36 UTC
Permalink
Just guessing, is the name of libdl2.so matching one of the system libraries
that is in /system/lib/"libdl2.so" ?
The system library might be already mapped in your process' address space,
and libdl1.so fails to link because it doesn't find the symbol it expects.

One solution might be to change the name of "libdl2.so" to something
slightly different.

There should be a logcat message prior to the link_image one explaining the
reason for the failure.
Post by fycd
in froyo. I made two lib: libdl1.so and libdl2.so.
libdl1.so load libdl2.so by dlopen();
and i wrote an executable file "Loadlibfile" witch to test the
libdl2.so
also. I wrote an apk "myApk" to load libdl1.so by System.loadLibrary()
I push the Loadlibfile into /data/data/com.myApk/lib/ (libdl1.so and
libdl2.so are there, too),
and execute ./Loadlibfile. It load libdl2.so well.
but when i run myApk in emulator ,it shows error: "dlopen
link_image[1995]: failed to link 'libdl2.so'" ==>
(load by dlopen("/data/data/com.myApk/lib/libdl2.so") ).
and
" find_library[1188]: 37 'libdl2.so' failed to load previously" ==>
(load by dlopen("./libdl2.so") or dlopen("libdl2.so") )
Please some one help fix it. it has troubled me for a week's long...
T_T
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-***@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
阎宙勋
2010-12-03 09:29:59 UTC
Permalink
thx to David Turner's help :)
&
hi all:
I change my library's name to libmydl2.so. and still get the error log.
I build a new linker with debug mode and find my problem: I decleared an
"extern int gi_i" in libmydl2.so , which is defined in libdl1.so.
but the linker in android system can't find the gi_i in the libdl1.so. so it
link libmydl2.so failed.
After i comment the "extern int gi_i", it works.

but now, my new question is : how could i use "extern" variable in
android?

as the mail before, "Loadlibfile" works well with "extern" while "myApk"
doesn't...someone advise?


and if some like to build a debug linker in android, see:
http://forum.xda-developers.com/showthread.php?t=704561&page=6

*
*
Post by David Turner
Just guessing, is the name of libdl2.so matching one of the system
libraries that is in /system/lib/"libdl2.so" ?
The system library might be already mapped in your process' address space,
and libdl1.so fails to link because it doesn't find the symbol it expects.
One solution might be to change the name of "libdl2.so" to something
slightly different.
There should be a logcat message prior to the link_image one explaining the
reason for the failure.
Post by fycd
in froyo. I made two lib: libdl1.so and libdl2.so.
libdl1.so load libdl2.so by dlopen();
and i wrote an executable file "Loadlibfile" witch to test the
libdl2.so
also. I wrote an apk "myApk" to load libdl1.so by System.loadLibrary()
I push the Loadlibfile into /data/data/com.myApk/lib/ (libdl1.so and
libdl2.so are there, too),
and execute ./Loadlibfile. It load libdl2.so well.
but when i run myApk in emulator ,it shows error: "dlopen
link_image[1995]: failed to link 'libdl2.so'" ==>
(load by dlopen("/data/data/com.myApk/lib/libdl2.so") ).
and
" find_library[1188]: 37 'libdl2.so' failed to load previously" ==>
(load by dlopen("./libdl2.so") or dlopen("libdl2.so") )
Please some one help fix it. it has troubled me for a week's long...
T_T
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-***@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
阎宙勋
2010-12-03 10:35:48 UTC
Permalink
hi all:
I fixed my new issue. now it works well in myApk.

my fault is that even the libmydl2.so doesn't be loaded by myApk, it still
must be added in myApk's Android.mk like this:
LOCAL_JNI_SHARED_LIBRARIES := libdl1 libmydl2

and in the libmydl2.so 's Android.mk .add
"LOCAL_SHARED_LIBRARIES := libdl1"

I don't kown why LOCAL_LDLIBS doesn't work. so I use LOCAL_SHARED_LIBRARIES
instead.

ps: build a linker with debug is very helpful while getting problems in
linking libs. :)
Post by 阎宙勋
thx to David Turner's help :)
&
I change my library's name to libmydl2.so. and still get the error log.
I build a new linker with debug mode and find my problem: I decleared
an "extern int gi_i" in libmydl2.so , which is defined in libdl1.so.
but the linker in android system can't find the gi_i in the libdl1.so. so
it link libmydl2.so failed.
After i comment the "extern int gi_i", it works.
but now, my new question is : how could i use "extern" variable in
android?
as the mail before, "Loadlibfile" works well with "extern" while
"myApk" doesn't...someone advise?
http://forum.xda-developers.com/showthread.php?t=704561&page=6
*
*
Just guessing, is the name of libdl2.so matching one of the system
Post by David Turner
libraries that is in /system/lib/"libdl2.so" ?
The system library might be already mapped in your process' address space,
and libdl1.so fails to link because it doesn't find the symbol it expects.
One solution might be to change the name of "libdl2.so" to something
slightly different.
There should be a logcat message prior to the link_image one explaining
the reason for the failure.
Post by fycd
in froyo. I made two lib: libdl1.so and libdl2.so.
libdl1.so load libdl2.so by dlopen();
and i wrote an executable file "Loadlibfile" witch to test the
libdl2.so
also. I wrote an apk "myApk" to load libdl1.so by System.loadLibrary()
I push the Loadlibfile into /data/data/com.myApk/lib/ (libdl1.so and
libdl2.so are there, too),
and execute ./Loadlibfile. It load libdl2.so well.
but when i run myApk in emulator ,it shows error: "dlopen
link_image[1995]: failed to link 'libdl2.so'" ==>
(load by dlopen("/data/data/com.myApk/lib/libdl2.so") ).
and
" find_library[1188]: 37 'libdl2.so' failed to load previously" ==>
(load by dlopen("./libdl2.so") or dlopen("libdl2.so") )
Please some one help fix it. it has troubled me for a week's long...
T_T
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-***@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
Angus Lees
2010-12-03 13:27:14 UTC
Permalink
Post by 阎宙勋
thx to David Turner's help :)
&
I change my library's name to libmydl2.so. and still get the error log.
I build a new linker with debug mode and find my problem: I decleared
an "extern int gi_i" in libmydl2.so , which is defined in libdl1.so.
but the linker in android system can't find the gi_i in the libdl1.so. so
it link libmydl2.so failed.
After i comment the "extern int gi_i", it works.
but now, my new question is : how could i use "extern" variable in
android?
as the mail before, "Loadlibfile" works well with "extern" while
"myApk" doesn't...someone advise?
Heh, I also spent ages debugging this same problem. It turns out Android
2.0+ always treats dlopen() as if RTLD_LOCAL was specified. This means
symbols needed by the library being loaded have to be in libraries that that
library in turn links to - you can't just assume it will find symbols in
whatever is currently loaded.

More specifically, your library needs a DT_NEEDED entry (at least
indirectly) for every library where it wants to find symbols. You get that
by adding "-lmylib" at link time (or whatever the equivalent in the NDK
makefile system is). You still need to actually load the dependent library
yourself manually first, because unfortunately the app lib dir isn't added
to the run time linker search path (and you can't change LD_LIBRARY_PATH
after initialisation).

In case you were wondering, this is also the _opposite_ of what Android did
before 2.0. Pre Android 2.0, dlopen() effectively always assumed
RTLD_GLOBAL. Luckily the above DT_NEEDED workaround should be harmless on
pre-2.0, so the same solution works across all versions. Enjoy.

- Gus
Post by 阎宙勋
http://forum.xda-developers.com/showthread.php?t=704561&page=6
*
*
Just guessing, is the name of libdl2.so matching one of the system
Post by David Turner
libraries that is in /system/lib/"libdl2.so" ?
The system library might be already mapped in your process' address space,
and libdl1.so fails to link because it doesn't find the symbol it expects.
One solution might be to change the name of "libdl2.so" to something
slightly different.
There should be a logcat message prior to the link_image one explaining
the reason for the failure.
Post by fycd
in froyo. I made two lib: libdl1.so and libdl2.so.
libdl1.so load libdl2.so by dlopen();
and i wrote an executable file "Loadlibfile" witch to test the
libdl2.so
also. I wrote an apk "myApk" to load libdl1.so by System.loadLibrary()
I push the Loadlibfile into /data/data/com.myApk/lib/ (libdl1.so and
libdl2.so are there, too),
and execute ./Loadlibfile. It load libdl2.so well.
but when i run myApk in emulator ,it shows error: "dlopen
link_image[1995]: failed to link 'libdl2.so'" ==>
(load by dlopen("/data/data/com.myApk/lib/libdl2.so") ).
and
" find_library[1188]: 37 'libdl2.so' failed to load previously" ==>
(load by dlopen("./libdl2.so") or dlopen("libdl2.so") )
Please some one help fix it. it has troubled me for a week's long...
T_T
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-***@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
阎宙勋
2010-12-05 11:57:30 UTC
Permalink
hi all:
I find a strange thing here in android 2.2 froyo:

the code follow will failed in the first dlopen():
dlopen("libDe.so"); //failed here and exit error shows:"can't find
"libDe.so" "
dlopen("./libDe.so"); //dosen't run here
dlopen("/data/data/com.revfycd.A2S/lib/libDe.so"); //dosen't run here
...
but the code follow will get through:
dlopen(/data/data/com.revfycd.A2S/lib/libDe.so"); //works well
dlopen("./libDe.so"); //works well
dlopen("libDe.so"); //works well


could someone tell me why? thx :)

fycd
Post by Angus Lees
Post by 阎宙勋
thx to David Turner's help :)
&
I change my library's name to libmydl2.so. and still get the error log.
I build a new linker with debug mode and find my problem: I decleared
an "extern int gi_i" in libmydl2.so , which is defined in libdl1.so.
but the linker in android system can't find the gi_i in the libdl1.so. so
it link libmydl2.so failed.
After i comment the "extern int gi_i", it works.
but now, my new question is : how could i use "extern" variable in
android?
as the mail before, "Loadlibfile" works well with "extern" while
"myApk" doesn't...someone advise?
Heh, I also spent ages debugging this same problem. It turns out Android
2.0+ always treats dlopen() as if RTLD_LOCAL was specified. This means
symbols needed by the library being loaded have to be in libraries that that
library in turn links to - you can't just assume it will find symbols in
whatever is currently loaded.
More specifically, your library needs a DT_NEEDED entry (at least
indirectly) for every library where it wants to find symbols. You get that
by adding "-lmylib" at link time (or whatever the equivalent in the NDK
makefile system is). You still need to actually load the dependent library
yourself manually first, because unfortunately the app lib dir isn't added
to the run time linker search path (and you can't change LD_LIBRARY_PATH
after initialisation).
In case you were wondering, this is also the _opposite_ of what Android did
before 2.0. Pre Android 2.0, dlopen() effectively always assumed
RTLD_GLOBAL. Luckily the above DT_NEEDED workaround should be harmless on
pre-2.0, so the same solution works across all versions. Enjoy.
- Gus
Post by 阎宙勋
http://forum.xda-developers.com/showthread.php?t=704561&page=6
*
*
Just guessing, is the name of libdl2.so matching one of the system
Post by David Turner
libraries that is in /system/lib/"libdl2.so" ?
The system library might be already mapped in your process' address
space, and libdl1.so fails to link because it doesn't find the symbol it
expects.
One solution might be to change the name of "libdl2.so" to something
slightly different.
There should be a logcat message prior to the link_image one explaining
the reason for the failure.
Post by fycd
in froyo. I made two lib: libdl1.so and libdl2.so.
libdl1.so load libdl2.so by dlopen();
and i wrote an executable file "Loadlibfile" witch to test the
libdl2.so
also. I wrote an apk "myApk" to load libdl1.so by System.loadLibrary()
I push the Loadlibfile into /data/data/com.myApk/lib/ (libdl1.so and
libdl2.so are there, too),
and execute ./Loadlibfile. It load libdl2.so well.
but when i run myApk in emulator ,it shows error: "dlopen
link_image[1995]: failed to link 'libdl2.so'" ==>
(load by dlopen("/data/data/com.myApk/lib/libdl2.so") ).
and
" find_library[1188]: 37 'libdl2.so' failed to load previously" ==>
(load by dlopen("./libdl2.so") or dlopen("libdl2.so") )
Please some one help fix it. it has troubled me for a week's long...
T_T
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-***@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
Angus Lees
2010-12-05 12:49:47 UTC
Permalink
Post by 阎宙勋
dlopen("libDe.so"); //failed here and exit error shows:"can't find
"libDe.so" "
dlopen("./libDe.so"); //dosen't run here
dlopen("/data/data/com.revfycd.A2S/lib/libDe.so"); //dosen't run here
...
The app library directory isn't in the dlopen() search path (unfortunately),
so you need to fully qualify the library path (Java System.loadLibrary()
does that for you before calling dlopen()). This is why the first call here
fails.
Post by 阎宙勋
dlopen(/data/data/com.revfycd.A2S/lib/libDe.so"); //works well
dlopen("./libDe.so"); //works well
dlopen("libDe.so"); //works well
Once the library is loaded, it gets stashed in a table under the library
"soname" ("libDe.so"). Your later dlopen() calls hit that same "cached"
entry and never actually make it as far as the filesystem.

You have to take advantage of this to load your dependent libraries, for
example. If liba depends on symbols in libb then you need to load libb
(with full file path) and then load liba (with full path). The dependency
listed in liba is just the unqualified "libb.so" soname, and it finds
libb.so by hitting the previously loaded entry.
Yes, this also means your package (and the Android base system) can't have
two libraries with the same base file name - this is potentially difficult
since you can't know the full list of Android system libraries on every
device ;)

- Gus
Post by 阎宙勋
could someone tell me why? thx :)
fycd
Post by Angus Lees
Post by 阎宙勋
thx to David Turner's help :)
&
I change my library's name to libmydl2.so. and still get the error log.
I build a new linker with debug mode and find my problem: I decleared
an "extern int gi_i" in libmydl2.so , which is defined in libdl1.so.
but the linker in android system can't find the gi_i in the libdl1.so. so
it link libmydl2.so failed.
After i comment the "extern int gi_i", it works.
but now, my new question is : how could i use "extern" variable in
android?
as the mail before, "Loadlibfile" works well with "extern" while
"myApk" doesn't...someone advise?
Heh, I also spent ages debugging this same problem. It turns out Android
2.0+ always treats dlopen() as if RTLD_LOCAL was specified. This means
symbols needed by the library being loaded have to be in libraries that that
library in turn links to - you can't just assume it will find symbols in
whatever is currently loaded.
More specifically, your library needs a DT_NEEDED entry (at least
indirectly) for every library where it wants to find symbols. You get that
by adding "-lmylib" at link time (or whatever the equivalent in the NDK
makefile system is). You still need to actually load the dependent library
yourself manually first, because unfortunately the app lib dir isn't added
to the run time linker search path (and you can't change LD_LIBRARY_PATH
after initialisation).
In case you were wondering, this is also the _opposite_ of what Android
did before 2.0. Pre Android 2.0, dlopen() effectively always assumed
RTLD_GLOBAL. Luckily the above DT_NEEDED workaround should be harmless on
pre-2.0, so the same solution works across all versions. Enjoy.
- Gus
Post by 阎宙勋
http://forum.xda-developers.com/showthread.php?t=704561&page=6
*
*
Just guessing, is the name of libdl2.so matching one of the system
Post by David Turner
libraries that is in /system/lib/"libdl2.so" ?
The system library might be already mapped in your process' address
space, and libdl1.so fails to link because it doesn't find the symbol it
expects.
One solution might be to change the name of "libdl2.so" to something
slightly different.
There should be a logcat message prior to the link_image one explaining
the reason for the failure.
Post by fycd
in froyo. I made two lib: libdl1.so and libdl2.so.
libdl1.so load libdl2.so by dlopen();
and i wrote an executable file "Loadlibfile" witch to test the
libdl2.so
also. I wrote an apk "myApk" to load libdl1.so by System.loadLibrary()
I push the Loadlibfile into /data/data/com.myApk/lib/ (libdl1.so and
libdl2.so are there, too),
and execute ./Loadlibfile. It load libdl2.so well.
but when i run myApk in emulator ,it shows error: "dlopen
link_image[1995]: failed to link 'libdl2.so'" ==>
(load by dlopen("/data/data/com.myApk/lib/libdl2.so") ).
and
" find_library[1188]: 37 'libdl2.so' failed to load previously" ==>
(load by dlopen("./libdl2.so") or dlopen("libdl2.so") )
Please some one help fix it. it has troubled me for a week's long...
T_T
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to android-***@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
Loading...