北海道に住みたいと言っているだけのブログ

力技

WindowsMinGWのJulius 4.2.2で,マルチスレッドを利用したA/D入力を行う方法.
既にMinGWにはlibthreadがインストールされているものとする.(参考;Windows用Pthreadインストール用メモ | demura.net: ロボットの開発と教育


libpthreadが存在しても,デフォルトの状態でconfigureすると

checking for POSIX thread library in -lpthread... no

と表示され,pthreadの機能を利用することができない.
念のため

./configure --enable-pthread

としても結果は同じ.
pthreadを使うlibjuliusのconfig.logを覗いてみると

configure:1965: checking for POSIX thread library in -lpthread
configure:1976: gcc -o conftest.exe -O6 -fomit-frame-pointer conftest.c -lpthread 1>&5
configure: 関数 'main' 内:
configure:1972:1: エラー: 1 番目の 'pthread_equal' の引数用の互換性がない型です
In file included from configure:1970:0:
c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/pthread.h:927:31: 備考: expected 'pthread_t' but argument is of type 'int'
configure:1972:1: エラー: 2 番目の 'pthread_equal' の引数用の互換性がない型です
In file included from configure:1970:0:
c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/pthread.h:927:31: 備考: expected 'pthread_t' but argument is of type 'int'
configure: failed program was:
#line 1969 "configure"
#include "confdefs.h"
#include
int main() {
pthread_equal(NULL,NULL);
; return 0; }

の記述があった.pthread_equalに渡す引数の型がいけませんよということらしい.
そこで,libjuliusディレクトリのconfigureの1967行目からを以下のように変更する.

cat > conftest.$ac_ext <<EOF
#line 1969 "configure"
#include "confdefs.h"
#include
int main() {
pthread_t a;
pthread_equal(a, a);
; return 0; }
EOF

適当なpthread_t型変数を定義してpthread_equalにぶちこむ.果たしてこれでいいのかは謎だけど.


こうするとconfigureできちんとpthreadが認識される.
ただしこのままだとコンパイル時にエラーが出てしまうので,libjulius/include/julius/recog.hの文頭に

#include

を追加すれば通るはず.
こうしてできたJuliusを--versionすると,「NoPthread」と出ていたのが消えているのがわかる.