Makefileがエラーを返す

I have a makefile that is supposed to compile a set of C files
which use the library. Although the makefile ran on my previous
Linux installation, I can’t get it running now. Can anyone help me
with this?

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

ベストアンサー

Put -lpthread at the end of the command line, after
the object file, which need symbols from
libthread.[a|so]

GNU
ld(および他のリンカー)が定義されていない参照を解決するとき、オブジェクトファイルとライブラリ内のシンボル定義のみを検索します。

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です