I have cloned and built the riscv-tools repository on my ubuntu machine. Hello world program works well.
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.
I made a very simple sample code to demonstrate my problem.
Here is my example.c file content
#include <stdio.h>
#include <math.h>
#include <pthread.h>
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(&my_lock, NULL);
printf("return code from pthread_mutex_init() is %d\n", rc);
printf("Example End!\n");
return 0;
}
Ok and here is my command line to compile it for the RISCV target
riscv64-unknown-elf-gcc -Wall -m32 -march=RV32IM -o example example.c -lm -lpthread
Here is the compiler output:
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(&my_lock, NULL);
^
example.c:10:13: warning: unused variable 'my_thread' [-Wunused-variable]
pthread_t my_thread;
^
Notice there is no problem with the math library, but the pthread library stuff yields errors.
Obviously compiling this simple example for X86 target works like a charm. The program output for X86 target is :
> ./example
Example start!
sqrt(16.0) = 4.000000
return code from pthread_mutex_init() is 0
Example End!
This is what we should eventually get when it compiles and runs on the RISCV target when doing this:
spike pk ./example
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 ?
Any help is appreciated!