title: What is proper way of linking C program with standard threads (<threads.h> from C11)?
body: <p>I'm trying to learn how to use  in C11, so I've tried to compile that example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;threads.h&gt;
  
  int run(void *arg)
  {
      printf("Hello world of C11 threads from thread %lu.\n", thrd_current());
      fflush(stdout);
      return 0;
  }
  
  int main()
  {
      thrd_t thread;
      if (thrd_success != thrd_create(&amp;thread, run, NULL))
      {
          perror("Error creating thread!");
          return 1;
      }
  
      int result;
      thrd_join(thread, &amp;result);
      printf("Thread %lu returned %d at the end\n", thread, result);
      fflush(stdout);
  }
  </code></pre>
  
  <p>The problem is that the program needs to be compiled with extra linker flags:</p>
  
  <pre><code>$ gcc --std=c17 main.c
  /usr/bin/ld: /tmp/ccEtxJ6l.o: in function `main':
  main.c:(.text+0x66): undefined reference to `thrd_create'
  /usr/bin/ld: main.c:(.text+0x90): undefined reference to `thrd_join'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>But nowhere is information what flags should I use, I've noticed, that compilation with <code>-lpthread</code> flag is succesfull:</p>
  
  <pre><code>$ gcc --std=c17 main.c -lpthread &amp;&amp; ./a.out 
  Hello world of C11 threads from thread 140377624237824.
  Thread 140377624237824 returned 0 at the end
  </code></pre>
  
  <p>But it does not mean that it is right flag.
  I'm using gcc:</p>
  
  <pre><code>$ gcc --version
  gcc (Arch Linux 9.3.0-1) 9.3.0
  </code></pre>