I'm creating new threads in a function, and I've included pthread.h. But it's not working, I keep receiving the following error upon compiling:
undefined reference to `pthread_create'
The flags I'm using to compile are the following:
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
The compiler is gcc
Makefile:
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
CFLAGSis normally the wrong variable to put linked libraries into, many build systems put theCFLAGSon the command line before the files to be linked. Your build system might offer aLIBSvariable where you can put-pthread. Not enough information to tell for sure. - user2371524gcc -o$@ $(CFLAGS) $<for linking.-pthreadmust appear after the input files. - user2371524$(CC) -o mfind stack.o list.o mfind.ois-pthreador a variable that contains-pthread? - Chris Turner