2011-11-13 6 views
0

私は、<pthread.h>ライブラリを使用するCファイルのセットをコンパイルするはずのmakefileを持っています。私の以前のLinuxインストールでmakefileが実行されましたが、今は実行できません。誰もこれで私を助けることができますか?Makefileがエラーを返す

CC=gcc 
CFLAGS=-c -std=c99 
LDFLAGS= -lpthread 
SOURCES=pc_0.c stak.h 
OBJECTS=$(SOURCES:.c=.o) 
EXECUTABLE=pcths 

all: $(SOURCES) $(EXECUTABLE) 
$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(LDFLAGS) $(OBJECTS) -o [email protected] 

.c.o: 
    $(CC) $< -o [email protected] $(CFLAGS) 
clean: 
    rm -f *.o core 

シェルプロンプトで「make」と入力したときに表示されるエラーメッセージは次のとおりです。私は手動で次の手順を実行した場合

gcc pc_0.c -o pc_0.o -c -std=c99 
pc_0.c: In function ‘main’: 
pc_0.c:25:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default] 
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)()’ 
pc_0.c:29:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default] 
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)()’ 
pc_0.c:33:2: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default] 
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)()’ 
gcc -lpthread pc_0.o stak.h -o pcths 
pc_0.o: In function `main': 
pc_0.c:(.text+0x100): undefined reference to `pthread_create' 
pc_0.c:(.text+0x15d): undefined reference to `pthread_create' 
pc_0.c:(.text+0x1ba): undefined reference to `pthread_create' 
pc_0.c:(.text+0x206): undefined reference to `pthread_join' 
pc_0.c:(.text+0x21a): undefined reference to `pthread_join' 
pc_0.c:(.text+0x22e): undefined reference to `pthread_join' 
collect2: ld returned 1 exit status 
make: *** [pcths] Error 1 

しかし、ソースがコンパイルされています

cc pc_0.c -o pc_0.o -c -std=c99 
cc pc_0.o -o pcths -lpthread 
+3

エラーメッセージも投稿できますか? – Martijn

+0

'stak.h 'の扱いが間違っています。両方のシステムで同じバージョンのgccを使用していますか? – Beta

+0

エラーなしで、ちょうど推測ですが、libc-devがインストールされていますか? – Marc

答えて

0

GNU ldの(および他のリンカー)はオブジェクトファイルのみで、それはシンボル定義を探し未定義の参照を解決するときlibthread.[a|so]

からシンボルを必要とされ、オブジェクトファイルの後に、コマンドラインの末尾に-lpthreadを入れて、前記参照を含む前記オブジェクトの後に続くライブラリ。

+0

ありがとう、それは私の問題を解決しました – uyetch

0

ことがあるが、私はいつも投稿

0

変数の代入の周り「」追加いかに重要かわかりません実際のエラーメッセージは、問題をデバッグする際に最も重要です。

おそらく問題はありませんが、通常はインデント用にタブの代わりにスペースを使用するようにエディタ(emacs)を設定しています。これがmakeの問題です。私はすべてを強調表示し、問題を解決するためにm-x tabifyを実行する必要があります。