ubuntu マシンに riscv-tools リポジトリを複製して構築しました。Hello world プログラムはうまく機能します。
現在、アプリケーションを X86 ターゲットから riscv (RV32IM) ターゲットに移植しようとしています。私のアプリケーションは数学ライブラリと pthread ライブラリに依存しています。コードで pthread.h ヘッダー ファイルの宣言を使用しようとすると、問題が発生します。
私の問題を示すために、非常に単純なサンプル コードを作成しました。
これが私のexample.cファイルの内容です
#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;
}
わかりました。RISCV ターゲット用にコンパイルするためのコマンド ラインを次に示します。
riscv64-unknown-elf-gcc -Wall -m32 -march=RV32IM -o example example.c -lm -lpthread
コンパイラの出力は次のとおりです。
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;
^
数学ライブラリには問題がありませんが、pthread ライブラリのものはエラーになることに注意してください。
明らかに、この単純な例を X86 ターゲット用にコンパイルすると、魅力的に機能します。X86 ターゲットのプログラム出力は次のとおりです。
> ./example
Example start!
sqrt(16.0) = 4.000000
return code from pthread_mutex_init() is 0
Example End!
RISCV ターゲットでコンパイルして実行すると、最終的に次のようになります。
spike pk ./example
RISCV ツール チェーンの pthread ライブラリの問題は何ですか? RISCVコミュニティの誰でもそれを再現できますか? 同じ問題が発生している人はいますか?
どんな助けでも大歓迎です!