Sooora
Sooora

Reputation: 191

compiling multithreading C example with riscv gnu cross compiler

I'm using homebrew-riscv toolchain on mac machine.

I want to compile a simple multithreading program that is written using pthread library in C using riscv gnu cross compiler. So that, I've used the below command:

riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 pthreadExample.c -o pthreadExample -lpthread

And I've got the following warning and error:

warning: implicit declaration of function 'pthread_create' [-Wimplicit-function-declaration]
   32 |         pthread_create(&tid, NULL, myThreadFun, (void *)&tid);
      |         ^~~~~~~~~~~~~~
pthreadExample.c:34:5: warning: implicit declaration of function 'pthread_exit' [-Wimplicit-function-declaration]
   34 |     pthread_exit(NULL);
      |     ^~~~~~~~~~~~
/opt/homebrew/Cellar/riscv-gnu-toolchain/master/lib/gcc/riscv64-unknown-elf/11.1.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lpthread
collect2: error: ld returned 1 exit status

Does anyone have any ideas for solving this error? Or should I use another option instead of -lpthread for compiling?

Thanks in advance

Upvotes: 1

Views: 1049

Answers (1)

vfiskewl
vfiskewl

Reputation: 70

you are using the bare metal cross compiler, what you need is:

riscv64-unknown-linux-gnu-gcc

additionally, you are using the -march=rv32i flag, but you are using the 64 bit version of the compiler, that doesn't seem correct to me. If the target machine is a 32 bit one, then perhaps you should use the riscv32-unknown-linux-gnu-gcc

Upvotes: 1

Related Questions