link errors: pthread and librt

2,202 views
Skip to first unread message

Tony Jiang

unread,
Nov 25, 2010, 8:41:42 PM11/25/10
to android-ndk
Hi,

Here are some link errors in Android NDK. They are about pthread and
librt:
core_thread.c:(.text+0x13d4): undefined reference to `pthread_cancel'
core_queue.c:(.text+0x298): undefined reference to `mq_timedreceive'
core_queue.c:(.text+0x2a0): undefined reference to `__errno_location'
core_queue.c:(.text+0x390): undefined reference to `mq_close'
core_queue.c:(.text+0x3bc): undefined reference to `mq_unlink'
core_queue.c:(.text+0x4e8): undefined reference to `mq_timedsend'
core_queue.c:(.text+0x4f4): undefined reference to `__errno_location'
core_queue.c:(.text+0x96c): undefined reference to `mq_open'

Do I need to implement "pthread_cancel"?
How about "__errno_location"?
For mq_*, I add LOCAL_LDLIBS := -lrt, but ld don't find librt.

Regards,
Tony

Christian Linne

unread,
Nov 26, 2010, 4:42:16 AM11/26/10
to andro...@googlegroups.com
(1) 'pthread_cancel' isn't implemented, and you should avoid to use it if possible - it leaves the thread in an undefined state, used resources aren't freed, etc. Setting up a condition to let the thread run out should be preferred.
 
(2) librt.so cannot be found because it's not in the NDK. I don't know if it will ever be.
 
(3) Haven't found '__errno_location' anywhere in the NDK, so it's not surprising the linker complains about it.
 
2010/11/26 Tony Jiang <tonyji...@gmail.com>

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




--
_________
Mit freundlichen Grüßen
Yours sincerely

Christian Linne

Mail (private): linn...@aol.com
Mail (official): Christi...@googlemail.com,
ICQ: 293253013

Tony Jiang

unread,
Nov 26, 2010, 6:07:11 AM11/26/10
to android-ndk
Hi Christian,
Thank you for your reply.
(1) 'pthread_cancel' exists in our old sdk, we must have it.
(2) How to resolve: undefined reference to `mq_*' ?
(3) Our old sdk seems to have to use ''__errno_location',

Best Regards,
Tony

On 11月26日, 下午5时42分, Christian Linne <christian.li...@googlemail.com>
wrote:
> (1) 'pthread_cancel' isn't implemented, and you should avoid to use it if
> possible - it leaves the thread in an undefined state, used resources
> aren't freed, etc. Setting up a condition to let the thread run out should
> be preferred.
>
> (2) librt.so cannot be found because it's not in the NDK. I don't know if it
> will ever be.
>
> (3) Haven't found '__errno_location' anywhere in the NDK, so it's not
> surprising the linker complains about it.
>
> 2010/11/26 Tony Jiang <tonyjiang2...@gmail.com>
>
>
>
> > Hi,
>
> > Here are some link errors in Android NDK. They are about pthread and
> > librt:
> > core_thread.c:(.text+0x13d4): undefined reference to `pthread_cancel'
> > core_queue.c:(.text+0x298): undefined reference to `mq_timedreceive'
> > core_queue.c:(.text+0x2a0): undefined reference to `__errno_location'
> > core_queue.c:(.text+0x390): undefined reference to `mq_close'
> > core_queue.c:(.text+0x3bc): undefined reference to `mq_unlink'
> > core_queue.c:(.text+0x4e8): undefined reference to `mq_timedsend'
> > core_queue.c:(.text+0x4f4): undefined reference to `__errno_location'
> > core_queue.c:(.text+0x96c): undefined reference to `mq_open'
>
> > Do I need to implement "pthread_cancel"?
> > How about "__errno_location"?
> > For mq_*, I add LOCAL_LDLIBS := -lrt, but ld don't find librt.
>
> > Regards,
> > Tony
>
> > --
> > 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<android-ndk%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.
>
> --
> _________
> Mit freundlichen Grüßen
> Yours sincerely
>
> Christian Linne
>
> Mail (private): linne2...@aol.com
> Mail (official): Christian.Li...@googlemail.com,
> ICQ: 293253013

alan

unread,
Nov 26, 2010, 10:12:24 AM11/26/10
to android-ndk
1) Do you really need pthread_cancel? could you implement your code in
another way without pthread_cancel?
2) Could you implement your own message queue (or compile in the
source of an existing implementation)?
3) what does it need it for? could you provide a dummy implementation?

David Turner

unread,
Nov 26, 2010, 10:24:51 AM11/26/10
to andro...@googlegroups.com
On Fri, Nov 26, 2010 at 10:42 AM, Christian Linne <christi...@googlemail.com> wrote:
(1) 'pthread_cancel' isn't implemented, and you should avoid to use it if possible - it leaves the thread in an undefined state, used resources aren't freed, etc. Setting up a condition to let the thread run out should be preferred.
 
(2) librt.so cannot be found because it's not in the NDK. I don't know if it will ever be.
 
Like pthread, the corresponding features are in the C library itself. Not all librt features are implemented though. Essentially, you don't need -lpthread -rt when linking binaries for Android.

Tony Jiang

unread,
Nov 26, 2010, 10:46:01 PM11/26/10
to android-ndk

Hi Alan,
(1) I will try to implement my code in another way without
pthread_cancel.
(2) And I will try to implement my own message queue.

Regards,
Tony
Reply all
Reply to author
Forward
0 new messages