gcc "lto1: fatal error" (LTO object/version mismatch) in CI
LTO embeds compiler-version-specific bytecode in each object. When objects are produced by different GCC versions or with mismatched flags, lto1 cannot merge them and aborts.
What this error means
A link with -flto fails with "lto1: fatal error", often citing an incompatible LTO bytecode version or a missing/garbled GIMPLE section.
gcc
lto1: fatal error: bytecode stream in file 'libfoo.a' generated with
LTO version 11.0 instead of the expected 12.1
compilation terminated.Common causes
How to fix it
Rebuild everything with one toolchain
- Compile all objects and dependencies with the same GCC version and LTO flags.
- Or disable LTO on prebuilt libraries that you cannot rebuild.
gcc
make clean && CXX=g++-12 make CXXFLAGS="-flto" # uniform compiler + flagsHow to prevent it
- Pin one compiler version and a consistent LTO flag set across the whole build, and avoid mixing LTO archives from another toolchain.
Related guides
ld "Killed signal terminated" / out-of-memory linker in CIFix ld being OOM-killed in CI - linking a large binary (especially with debug info or LTO) exhausted runner m…
ld "undefined reference to std::__throw_*" (libstdc++ version) in CIFix ld "undefined reference to std::__throw_..." in CI - objects built against a newer libstdc++ are linked t…