undefined reference to `pthread_create' -pthread not working
我正在一个函数中创建新的线程,我已经包含pthread.h。但是它不起作用,我在编译时一直收到以下错误:
undefined reference to `pthread_create'
号
我用来编译的标志如下:
CFLAGS=-std=gnu99 -pthread -g -Wall -Wextra -Werror
-Wmissing-declarations -Wmissing-prototypes -Werror-implicit-function-declaration -Wreturn-type -Wparentheses -Wunused -Wold-style-definition -Wundef -Wshadow -Wstrict-prototypes -Wswitch-default -Wunreachable-code
号
编译器是gcc
生成文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | CC=gcc CFLAGS=-std=gnu99 -pthread -g -Wall -Wextra -Werror -Wmissing-declarations -Wmissing-prototypes -Werror-implicit-function-declaration -Wreturn-type -Wparentheses -Wunused -Wold-style-definition -Wundef -Wshadow -Wstrict-prototypes -Wswitch-default -Wunreachable-code all: finder finder: stack.o list.o finder.o $(CC) -o mfind stack.o list.o mfind.o stack.o: stack.c stack.h $(CC) -c stack.c $(CFLAGS) list.o: list.c list.h $(CC) -c list.c $(CFLAGS) finder.o: finder.c finder.h $(CC) -c finder.c $(CFLAGS) clean: rm -f *.o finder |
在链接阶段需要
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | CC=gcc CFLAGS=-std=gnu99 -g -Wall -Wextra -Werror -Wmissing-declarations -Wmissing-prototypes -Werror-implicit-function-declaration -Wreturn-type -Wparentheses -Wunused -Wold-style-definition -Wundef -Wshadow -Wstrict-prototypes -Wswitch-default -Wunreachable-code LIBS=-pthread all: finder finder: stack.o list.o finder.o $(CC) -o mfind stack.o list.o mfind.o $(LIBS) stack.o: stack.c stack.h $(CC) -c stack.c $(CFLAGS) list.o: list.c list.h $(CC) -c list.c $(CFLAGS) finder.o: finder.c finder.h $(CC) -c finder.c $(CFLAGS) clean: rm -f *.o finder |