I got this error when installing ruby (1.9.2) on my fresh install Mountain Lion. Looking at some references online, this looks like an issue with the compiler used in mac os (lion and mountain lion), as they switched to (LLVM) Clang compilers.
Work-around I found for my ruby installation is to specify the compiler to use during the installation (clang), change the default GCC to Clang.
Also, make sure you have the following installed and up to date for ruby install:
xcode with “Command Line Tools” components
Note: This could also be the case with other packages compiled/installed from source.