Page MenuHomePhabricator

pthread not found in applications using thread
Open, NormalPublic

Description

in Etui, i use threads. I have this error :

In file included from /usr/include/eina-1/eina/eina_inline_lock_posix.x:35,
                 from /usr/include/eina-1/eina/eina_lock.h:100,
                 from /usr/include/eina-1/Eina.h:250,
                 from ../src/lib/etui_file.c:24:
/usr/include/pthread.h: At top level:
/usr/include/pthread.h:889:33: error: unknown type name ‘pthread_rwlock_t’; did you mean ‘pthread_cond_t’?
  889 | extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
      |                                 ^~~~~~~~~~~~~~~~
      |                                 pthread_cond_t

is it normal that I have to specify in etui's meson.build that I need to link against pthread ? Shouldn't instead eina.pc pass -lpthread to Libs ?

vtorri created this task.Mon, Oct 7, 2:21 AM
vtorri triaged this task as Normal priority.

My eina.pc contains -lpthread ...

vtorri added a comment.Wed, Oct 9, 3:26 AM

it is garded. adding -D_POSIX_C_SOURCE=200809L in eina.pc (in CFlags) should be sufficient

#if defined __USE_UNIX98 || defined __USE_XOPEN2K
/* Data structure for reader-writer lock variable handling.  The
   structure of the attribute type is deliberately not exposed.  */
typedef union
{
  struct __pthread_rwlock_arch_t __data;
  char __size[__SIZEOF_PTHREAD_RWLOCK_T];
  long int __align;
} pthread_rwlock_t;
bu5hm4n edited projects, added efl: data types; removed efl.Wed, Oct 9, 4:17 AM
bu5hm4n removed bu5hm4n as the assignee of this task.
bu5hm4n added a subscriber: bu5hm4n.

This needs some solving in either your app or eina, but not in meson. eina.pc should not force you to -D_POSIX_C_SOURCE i guess. autotools also never did that.

AJSlye added a subscriber: AJSlye.EditedWed, Oct 9, 5:55 AM

Well, my eina.pc contains -pthread and I have the same issue/errors.

Now, even if I change the eina.pc lines to -lpthread, I still get the same errors.

https://github.com/vtorri/etui/issues/37

vtorri added a comment.Wed, Oct 9, 5:58 AM

@bu5hm4n i would say in eina as a user should not do extra work. Eina is using some features, it should enable them, imho.

raster added a comment.Wed, Oct 9, 7:26 AM

eina headers have to solve this because eina_inline_lock_posix.x has the implementation and it needs to #define enough to ensure the headers it has other 3rd part apps use have everything working. so:

#define _POSIX_C_SOURCE=200809

inside eina_inline_lock_posix.x at the top right after:

#ifndef EINA_INLINE_LOCK_POSIX_X_
#define EINA_INLINE_LOCK_POSIX_X_

@vtorri - can you try adding that there and see if it helps you? i assume this is not on windows in this case.

vtorri added a comment.Wed, Oct 9, 7:39 AM

@raster i've asked the user to export it to CPPFLAGS and issue vanished of course. I will provide a diff

vtorri added a comment.Wed, Oct 9, 7:46 PM

@raster btw, eina_inline_posix_lock.x does:

#include <errno.h>
#ifndef __USE_UNIX98
# define __USE_UNIX98
# include <pthread.h>
# undef __USE_UNIX98
#else
# include <pthread.h>
#endif

so normally, __USE_UNIX_98 is defined before inclusion of pthread.h, hence (https://phab.enlightenment.org/T8310#144612) pthread_rwlock_t is defined, right ?

vtorri added a comment.EditedWed, Oct 9, 8:04 PM

we can also increase _XOPEN_SOURCE to 700 (http://man7.org/linux/man-pages/man7/feature_test_macros.7.html)