9

I am porting a windows library to linux. I need to use timed join to wait for the thread to join in a specific timeout.

When I compile the library on Linux I am getting the warning

Implicit declaration of the function - pthread_timedjoin_np

I have included pthread.h and have compiled with -lpthread link. I know that pthread_timedjoin_np is a non-standard GNU function. The function first appeared in glibc in version 2.3.3. and somewhere in BCD v6.

I even checked the Man Page for Linux but got no help. How do I avoid this warning? Any help?

Edit-1: My system is RedHat 5.

Connor Low
  • 5,900
  • 3
  • 31
  • 52
jparthj
  • 1,606
  • 3
  • 20
  • 44

1 Answers1

17

Make sure the #define _GNU_SOURCE is before any of the your headers are included. Macros are set up by <features.h>, which include various parts of the GNU C library. If you've included other headers before you define _GNU_SOURCE, <features.h> will have already been included and will have not seen _GNU_SOURCE.

Even easier, just define it with the compiler adding -D_GNU_SOURCE as a compiler flag.

Collin
  • 11,977
  • 2
  • 46
  • 60
  • @jparthj Can you show your code (at least where you're including headers) and the command you're using to compile this file? – Collin Feb 27 '14 at 15:27
  • 2
    @Collin, I have had the same issue and your answer solves it !! Thanks. As you said, `#define _GNU_SOURCE` MUST be before any of headers included. – ogs Feb 05 '16 at 10:15