【发布时间】:2022-01-06 12:34:17
【问题描述】:
我在 mac 机器上使用 homebrew-riscv 工具链。
我想编译一个简单的多线程程序,该程序使用 riscv gnu 交叉编译器在 C 中使用 pthread 库编写。因此,我使用了以下命令:
riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 pthreadExample.c -o pthreadExample -lpthread
我收到以下警告和错误:
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
有没有人有解决这个错误的想法?还是应该使用其他选项而不是 -lpthread 进行编译?
提前致谢
【问题讨论】:
-
这是一个编译错误(-lpthread 是一个链接器命令)。尝试在该来源中包含
<pthread.h>。 -
@ErikEidt 感谢您的评论。
<pthread.h>已包含在源代码中。 -
试试
-pthread。请参阅:Significance of -pthread flag when compiling。 -
@ErikEidt 我已经尝试过了它导致了这个错误:
riscv64-unknown-elf-gcc: error: unrecognized command-line option '-pthread'
标签: compilation pthreads riscv