我有一个makefile应该编译一组使用<pthread.h>
库的C文件。虽然makefile在我之前的Linux安装上运行,但我现在无法运行它。谁能帮我这个?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
这是在我的shell提示符下键入“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
你也可以发布它给出的错误吗? – Martijn
'stak.h'的处理看起来不正确。您是否在两个系统上使用相同版本的gcc? – Beta
没有错误,只是一个猜测,但安装了libc-dev? – Marc