title: Does RISCV tool chain support pthread library?
body: <p>I have cloned and built the riscv-tools repository on my ubuntu machine. Hello world program works well.</p>
  
  <p>Now, I am trying to port an application from the X86 target to a riscv (RV32IM) target. My application depends on math and pthread libraries. I am experiencing problems when trying to use declarations from pthread.h header file in my code.</p>
  
  <p>I made a very simple sample code to demonstrate my problem.</p>
  
  <p>Here is my example.c file content</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;pthread.h&gt;
  
  int main(void) 
  { 
    float my_float;
    int rc;
  
    pthread_t my_thread;
    pthread_mutex_t my_lock;
  
    printf("Example start!\n"); 
  
    my_float = sqrt( 16.0 );
    printf("sqrt(16.0) = %f\n", my_float);
  
    rc = pthread_mutex_init(&amp;my_lock, NULL);
    printf("return code from pthread_mutex_init() is %d\n", rc);
  
    printf("Example End!\n"); 
  
    return 0; 
  }
  </code></pre>
  
  <p>Ok and here is my command line to compile it for the RISCV target</p>
  
  <pre><code>riscv64-unknown-elf-gcc -Wall -m32 -march=RV32IM -o example example.c -lm -lpthread
  </code></pre>
  
  <p>Here is the compiler output:</p>
  
  <pre><code>example.c: In function 'main':
  example.c:10:3: error: unknown type name 'pthread_t'
     pthread_t my_thread;
     ^
  example.c:11:3: error: unknown type name 'pthread_mutex_t'
     pthread_mutex_t my_lock;
     ^
  example.c:19:3: warning: implicit declaration of function 'pthread_mutex_init' [-Wimplicit-function-declaration]
     rc = pthread_mutex_init(&amp;my_lock, NULL);
     ^
  example.c:10:13: warning: unused variable 'my_thread' [-Wunused-variable]
     pthread_t my_thread;
               ^
  </code></pre>
  
  <p>Notice there is no problem with the math library, but the pthread library stuff yields errors.</p>
  
  <p>Obviously compiling this simple example for X86 target works like a charm. The program output for X86 target is :</p>
  
  <pre><code>&gt; ./example
   Example start!
   sqrt(16.0) = 4.000000
   return code from pthread_mutex_init() is 0
   Example End!
  </code></pre>
  
  <p>This is what we should eventually get when it compiles and runs on the RISCV target when doing this:</p>
  
  <pre><code>spike pk ./example
  </code></pre>
  
  <p>What is the problem with the pthread library in the RISCV tool chain ?
  Can anyone from RISCV community reproduce it ?
  Anyone experiencing the same issue ?</p>
  
  <p>Any help is appreciated!</p>