Search code examples
linuxg++tcsh

Redirect the output of g++ compiler to a file?


I see below messages while compiling an c++ program.

 test.cpp: In function ‘int main()’:
 test.cpp:950: error: no match for ‘operator<<’ in ‘std::cout << d->Derived::print()’
 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:117: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]

I was thinking if I can redirect all these messages to an file and do not see anything on the console. I have tried redirecting stderr messages by

g++ test.cpp 2> xx

But this does not seems to work. I still see everything on the console and nothing inside the file.


Solution

  • For csh type of shells, do:

    g++ test.cpp >& xx