I take it that somefile.txt is not a C source file (which is a special case of text file). In this case, do you want to capture the errors produced by gcc?
Error messages are usually sent to the standard error output stream, rather than the standard output that you are collecting with the system() command. You can use the shell to redirect standard error to standard output, so it can be captured, using 2>&1 like this:
gcc somefile.txt 2>&1
I don't know if PHP will send the parameter to system() through a shell. If not, you'll have to invoke one explicitly:
$output=system("sh -c 'gcc $filename 2>&1'");
The sh invokes the shell, the -c passes the next parameter as a command to the shell, and the single quotes around everything else keeps it together as one parameter.
Hope that helps,
— Robert J. Lee