I'm trying to compile something and include the pthread library in my makefile, but it doesn't seem to put it on the command line. If i type it directily into the command line it compiles, but if I try to use my makefile it comes up with errors along the lines of undefined refernce to pthread_join and such.
Here is my makefile
CC=gcc
all: pthreads
pthreads: pthreads.c
gcc -o pthreads pthreads.c -lpthread
You are missing the s
on the target line (ie you have pthread:
). So your rule isn't being run. The default (built-in) make rule is (and that rule doesn't have the -lpthread
bit).
You can either fix your typo or put -lpthread
in LDLIBS
and let the built-in rule do the compilation and linking for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.