You need to list all the .c files on the command line that contain code your program needs.
If test1.c calls a function in test2.c, then including test2.h is not enough. You need to execute this command to compile it:
Code:
gcc -g -lpthread -lm test.c test1.c test2.c
#include'ing the header only
informs test1.c that the function exists. The compiler doesn't automatically look at test2.c even though test1.c includes its header file.