cmake exception

-- Configuring done
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 130)
Aborted (core dumped)

    cmake ..

works fine, until I enter cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON … after this command I have the same output for next cmake .. inputs

gdb backtrace:

(gdb) bt
#0  0x00007ffff694b428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff694d02a in __GI_abort () at abort.c:89
#2  0x00007ffff6f8584d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/
#3  0x00007ffff6f836b6 in ?? () from /usr/lib/x86_64-linux-gnu/
#4  0x00007ffff6f83701 in std::terminate() () from /usr/lib/x86_64-linux-gnu/
#5  0x00007ffff6f83919 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/
#6  0x00007ffff6fac3f7 in std::__throw_out_of_range_fmt(char const*, ...) () from /usr/lib/x86_64-linux-gnu/
#7  0x00007ffff7016247 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::replace(unsigned long, unsigned long, char const*, unsigned long) () from /usr/lib/x86_64-linux-gnu/
#8  0x00000000006fd555 in cmMakefileTargetGenerator::WriteObjectBuildFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cmSourceFile const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) ()
#9  0x00000000006ff57d in cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile const&) ()
#10 0x00000000006ffe2f in cmMakefileTargetGenerator::WriteTargetBuildRules() ()
#11 0x000000000070b271 in cmMakefileLibraryTargetGenerator::WriteRuleFiles() ()
#12 0x00000000006f3d26 in cmLocalUnixMakefileGenerator3::Generate() ()
#13 0x00000000006c19bb in cmGlobalGenerator::Generate() ()
#14 0x00000000006cf853 in cmGlobalUnixMakefileGenerator3::Generate() ()
#15 0x0000000000561297 in cmake::Generate() ()
#16 0x0000000000561763 in cmake::Run(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) ()
#17 0x00000000004bdf94 in do_cmake(int, char const* const*) ()
#18 0x00000000004b98e6 in main ()

Tested on three Ubuntu distro. cmake versions: 3.10.0 and 3.5.1

What is the possible issue? Can`t find anything similar in Google at all

Is the project you’re running this on available publicly?

Cc: @kyle.edwards @brad.king CMake crash here. Looks like an underflow (that position is 0xffffffffffffffff) of some kind.

If it isn’t public, does the latest 3.19 release work?

This was also reported as CMake Issue 21506. It is a duplicate of CMake Issue 21471, and is fixed in 3.19.1.

For reference, this happens on projects that override CMake’s builtin CMAKE_C_COMPILE_OBJECT rule with one that is missing the <DEFINES> or <INCLUDES> placeholders.