OK. Never mind. I figure it out. The problem lies in the specs file I created using brew postinstall gcc, where the line: *cpp_unique_options: + -isystem /home/linuxbrew/.linuxbrew/include makes searching for stdlib.h in /scratch/.linuxbrew/include impossible for system header like cmath. This is a known issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129 Either removing that or change it to -I /home/linuxbrew/.linuxbrew/include solves the problem. -- Sent from: http://gcc.1065356.n8.nabble.com/gcc-Help-f629689.html