0

I'm using cmake to build a c++ project.

cmake -S . -B outputDir
cmake --build outputDir

When there's a compilation error, cmake --build complains with a large list of "note" messages, making the terminal too much verbose. For example, the following program:

#include <iostream>
int main()
{
    std::cout < "Hello world\n"; // Error: should be << 
    return 0;
}

Produces:

/home/user/githubRepos/cumath/main.cpp: In function ‘int main()’:
/home/user/githubRepos/cumath/main.cpp:7:15: error: no match for ‘operator<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘const char [13]’)
    7 |     std::cout < "Hello world\n";
      |     ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
      |          |      |
      |          |      const char [13]
      |          std::ostream {aka std::basic_ostream<char>}
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/stl_pair.h:454:5: note: candidate: ‘template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)’
  454 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_pair.h:454:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   ‘std::ostream’ {aka ‘std::basic_ostream<char>’} is not derived from ‘const std::pair<_T1, _T2>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:331:5: note: candidate: ‘template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)’
  331 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:331:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   ‘std::ostream’ {aka ‘std::basic_ostream<char>’} is not derived from ‘const std::reverse_iterator<_Iterator>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:369:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)’
  369 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:369:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   ‘std::ostream’ {aka ‘std::basic_ostream<char>’} is not derived from ‘const std::reverse_iterator<_Iterator>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:1163:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)’
 1163 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:1163:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   ‘std::ostream’ {aka ‘std::basic_ostream<char>’} is not derived from ‘const std::move_iterator<_IteratorL>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:1169:5: note: candidate: ‘template<class _Iterator> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)’
 1169 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:1169:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   ‘std::ostream’ {aka ‘std::basic_ostream<char>’} is not derived from ‘const std::move_iterator<_IteratorL>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/basic_string.h:6226:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
 6226 |     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6226:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   ‘std::ostream’ {aka ‘std::basic_ostream<char>’} is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/basic_string.h:6239:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)’
 6239 |     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6239:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   ‘std::ostream’ {aka ‘std::basic_ostream<char>’} is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/bits/basic_string.h:6251:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
 6251 |     operator<(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/basic_string.h:6251:5: note:   template argument deduction/substitution failed:
/home/user/githubRepos/cumath/main.cpp:7:17: note:   mismatched types ‘const _CharT*’ and ‘std::basic_ostream<char>’
    7 |     std::cout < "Hello world\n";
      |                 ^~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/bits/ios_base.h:46,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from /home/user/githubRepos/cumath/main.cpp:1:
/usr/include/c++/9/system_error:208:3: note: candidate: ‘bool std::operator<(const std::error_code&, const std::error_code&)’
  208 |   operator<(const error_code& __lhs, const error_code& __rhs) noexcept
      |   ^~~~~~~~
/usr/include/c++/9/system_error:208:31: note:   no known conversion for argument 1 from ‘std::ostream’ {aka ‘std::basic_ostream<char>’} to ‘const std::error_code&’
  208 |   operator<(const error_code& __lhs, const error_code& __rhs) noexcept
      |             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/9/system_error:282:3: note: candidate: ‘bool std::operator<(const std::error_condition&, const std::error_condition&)’
  282 |   operator<(const error_condition& __lhs,
      |   ^~~~~~~~
/usr/include/c++/9/system_error:282:36: note:   no known conversion for argument 1 from ‘std::ostream’ {aka ‘std::basic_ostream<char>’} to ‘const std::error_condition&’
  282 |   operator<(const error_condition& __lhs,
      |             ~~~~~~~~~~~~~~~~~~~~~~~^~~~~

By default, the only lines I'm interested in are the first lines:

/home/user/githubRepos/cumath/main.cpp: In function ‘int main()’:
/home/user/githubRepos/cumath/main.cpp:7:15: error: no match for ‘operator<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘const char [13]’)

Is there a way to remove the "note" level in cmake --build?

I've tried without luck:

cmake --build outputDir --log-level=WARNING

and

cmake --build outputDir -fcompare-debug-second

My cmake version is: 3.16.3

Thanks!

Wilem2
  • 172
  • 9
  • 1
    I think this is more about your compiler warning levels than CMake itself. Related: [https://unix.stackexchange.com/questions/547567/want-to-turn-off-note-level-messages-in-gcc](https://unix.stackexchange.com/questions/547567/want-to-turn-off-note-level-messages-in-gcc) – drescherjm Nov 12 '21 at 12:12
  • 3
    This has nothing to do with CMake, that's just error output of the compiler. You could filter the logs with e.g. `sed`. I do not think it is wise to remove them, the first error line is not always the one you need to fix, especially with templates. – Quimby Nov 12 '21 at 12:12
  • Thanks for your fast replies, Isn't cmake --build calling gcc in this case? Then cmake should have an option to pass the -fcompare-debug-second flag no? – Wilem2 Nov 12 '21 at 12:17
  • 2
    Related: [https://stackoverflow.com/questions/44284275/passing-compiler-options-cmake](https://stackoverflow.com/questions/44284275/passing-compiler-options-cmake) – drescherjm Nov 12 '21 at 12:19
  • 1
    The notes are important. The "error" message tells you where the compiler noticed the problem; the "note" messages tell you what it was doing when it noticed the problem. Often a problem is the result of misusing a template, and you need to know where the misuse occurred, not what the result of that misuse was. Reading error messages can be hard; you have to practice it! – Pete Becker Nov 12 '21 at 14:21

0 Answers0