visibility in NDK

1,601 views
Skip to first unread message

Kakyo

unread,
May 7, 2012, 11:55:15 AM5/7/12
to android-ndk
Hello,

I have two static libraries that share same helper function names.
In a shared lib I'd like to export only the API without the helper
function.
I tried with adding
__attribute__ ((visibility ("default"))) to my public APIs

and

__attribute__ ((visibility ("hidden"))) to my helper functions.

Then use
LOCAL_CPPFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
in my Android.mk of the static libs

also tried using
LOCAL_LDFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden
in my shared lib.

However, I'm still getting "multiple definition of 'helper()'" error
over the helper function (marked as hidden).

Any ideas would be appreciated.

K

David Turner

unread,
May 7, 2012, 12:31:29 PM5/7/12
to andro...@googlegroups.com
the visibility attributes and flags only control whether symbols are exported by a shared library (they also slightly modified how the function is called inside the generated machine code, but that's a bit off-topic).

however, the static linker will still see two different functions with the same name at link time, and complain, even if one of them is "hidden" in the ELF sense.

The only way that I see is to rename one of the functions.


K

--
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.


Kakyo

unread,
May 8, 2012, 6:27:28 AM5/8/12
to android-ndk
Thanks.
The problem was solved by using gcc's weak symbol attribute:
__attribute__ ((weak)) on the helper functions.

Reference: http://winfred-lu.blogspot.ca/2009/11/understand-weak-symbols-by-examples.html
> > "android-ndk" group.> To post to this group, send email toandr...@googlegroups.com.

pps

unread,
May 9, 2012, 3:14:23 AM5/9/12
to andro...@googlegroups.com
On Tuesday, May 8, 2012 6:27:28 AM UTC-4, Kakyo wrote:
Thanks.
The problem was solved by using gcc's weak symbol attribute:
__attribute__ ((weak)) on the helper functions.

Reference: http://winfred-lu.blogspot.ca/2009/11/understand-weak-symbols-by-examples.html


You could also declare it inline or __inline to get similar effect, but the helper function might actually get inlined. Linker will throw away duplicate instances of inline functions. I think inline functions that aren't inlined are marked with that "weak" elf symbol.


Reply all
Reply to author
Forward
0 new messages