This error message comes from the linker. The gnu linker doesn't search the math library by default - you need to customise the question, or edit its prototype, and add the "-lm" link argument. See https://coderunner.org.nz/mod/forum/discuss.php?d=172
I agree it seems a bit pathetic that you should have to do that, but it is the standard default Linux C behaviour. However, I'll update the built-in C and C++ question types to include the -lm link option in the next release. You'll still need to specify appropriate link options for other libraries, however.