When I tried to compile this program, it failed:
#include
#include
#include
#include
voi
Do
gcc -pthread -o name filename.c (cpp)
to compile the program, then
./name
to run the program.
You need to link pthread
library to your binary, like this:
cc -o myapp myapp.c -lpthread
You probably forgot to link with the Pthreads library (using -lpthread
on the command line).
For folks looking for the csapp solution. Compile "csapp.c" first, then
gcc -o filename filename.c csapp.o -lpthread
Others have mentioned that you haven't linked with the pthread library using the -lpthread
flag. Modern GCC (not sure how modern, mine is 4.3.3) allows you to use just -pthread
. From the man page:
-pthread
Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker.