Use the command gcc -Wall -o "test2" "test2.c" -lm
which will likely fix this.
This includes the math library in addition to the standard C runtime library. On most systems, the math library is historically a separate entity that needs to be explicitly requested.