dlsym returns Symbol not found

2,786 views
Skip to first unread message

aslam pa

unread,
Nov 2, 2010, 8:23:30 AM11/2/10
to android-ndk
I am trying to call an api from one shared library to another library
using dynamic loading.. Lets say calling from foo1.so to foo2.so. This
is the sample code fragment.

pHndl= dlopen(pTemp, RTLD_NOW);
if ((err = dlerror()) != NULL) {

LOGE("Error in loading shared lib: %s",err);

return NULL;

/* handle error, the symbol wasn't found */

}
dlerror();

dlsymRet = (OMX_PTR)dlsym(pHndl,pFuncName);

if ((err = dlerror()) != NULL) {

LOGE("Error symbol not found : %s",err);

return NULL;

/* handle error, the symbol wasn't found */

}


dlopen succeeds but dlsym returns null with error symbol not found. I
am actually calling an api within the static library inside foo2.so.

These are the things i tried.

Added
LOCAL_LDFLAGS += -Wl,--export-dynamic

in foo2.so make file.

I checked the pFuncName in foo2.so using "nm" and it is there . I
tried hardcodeing pFuncName also to the string.

Looks like some linker flag i am missing. I am running this on android
emulator. Both the modules are .c files except one wrapper file in
foo1.so is in cpp.


sample make file for foo2.so is given below

LOCAL_WHOLE_STATIC_LIBRARIES := \
libpv_aac_dec \

LOCAL_MODULE := libomx_aacdec
LOCAL_PRELINK_MODULE := false
LOCAL_LDFLAGS += -Wl,--export-dynamic

-include $(PV_TOP)/Android_platform_extras.mk

-include $(PV_TOP)/Android_system_extras.mk

LOCAL_SHARED_LIBRARIES += libomx_sharedlibrary libopencore_common

include $(BUILD_SHARED_LIBRARY)
include $(PV_TOP)/codecs_v2/omx/aacdec_comp/Android.mk
include $(PV_TOP)/codecs_v2/omx/algorithms/aacdec/Android.mk

David Turner

unread,
Nov 2, 2010, 2:28:33 PM11/2/10
to andro...@googlegroups.com
Are you sure the symbol is exported properly from the shared library. Such a file has two symbol tables: the "dynamic symbol table" (a.k.a. .dynsym) contains the symbols that can be resolved through dlsym(), while the simple "symbol table" (a.k.a. ".symtab") contains internal symbols, mostly used for debugging and can be removed from the file without impacting linking.

"objdump -T" will only dump dynamic symbols (instead of the simple ones), this should allow you to check this easily.


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@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.


Onur Cinar

unread,
Nov 2, 2010, 2:39:05 PM11/2/10
to andro...@googlegroups.com

Hi,

Looks like you are using the:

LOCAL_WHOLE_STATIC_LIBRARIES := \
       libpv_aac_dec          \


As far as I recall, this is no longer supported by the NDK, so I'm guessing that your functions may not be included in the shared library. Instead, you may want to try "-Wl,--whole-archive libpv_av_dec --Wl,--no-whole-archive" while linking. That may solve the problem.

Regards,

-onur




--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@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.

---
www.zdo.com

aslam pa

unread,
Nov 3, 2010, 1:16:45 AM11/3/10
to android-ndk
Hi Onur, David ,

I have tried the option suggested by Onur and it didnt work. Should i
add --export_dynamic into that.

Looks like symbols are not exported. I tried objdump -T of foo2.so
and it is not listing there. dumping .o file in which calling function
is defined. It is returning DYNAMIC SYMBOL TABLE: no symbols.

Looks like the problem is i am calling a function in the static
library inside a shared library. Static library symbols are not
exported to the shared library.

How to properly export symbols from the static library.
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .

aslam pa

unread,
Nov 3, 2010, 7:34:57 AM11/3/10
to android-ndk
When i wrapped my exported function with OSCL_EXPORT_REF it worked.
Now i can see in the exported symbols list and it worked.
Reply all
Reply to author
Forward
0 new messages