2011-11-13 123 views
0

我有一个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 
+3

你也可以发布它给出的错误吗? – Martijn

+0

'stak.h'的处理看起来不正确。您是否在两个系统上使用相同版本的gcc? – Beta

+0

没有错误,只是一个猜测,但安装了libc-dev? – Marc

回答

0

-lpthread在命令行结束时,目标文件,这就需要从libthread.[a|so]

符号后,当GNU LD(和其他接头)仅在目标文件解决未定义的引用,它查找符号定义和图书馆,后面的对象,其中包含上述引用。

+0

谢谢,它解决了我的问题 – uyetch

0

不知道它是多么的重要,但是我随时添加'周围的变量赋值

0

公示尝试调试您的问题时,实际的错误消息是至关重要的。

可能不是你的问题,但我通常设置我的编辑器(emacs)使用空格而不是制表符缩进,这会导致问题。我必须突出显示所有并运行m-x tabify来解决问题。