← Back to section · Tutorials & Labs
Systematic Debugging of Build Failures: Logs, Bisection and Minimal Reproductions
A general method for build failures: preserve the scene completely first, read the log from the first error, narrow the scope layer by layer with version, configuration and dependency bisection, and converge on a minimal reproduction.
Everyone hits build failures; the only difference is how they are handled. Some people search the last error line over and over, tweak configuration at random and burn an afternoon in place; others follow a fixed procedure and localize the problem to a single configuration line within half an hour. The difference is not experience but method. This tutorial gives a procedure that applies to any C/C++ and CMake-style project — preserving the scene, reading the log, bisecting, and reducing to a minimal reproduction — and it applies equally to PQC components such as liboqs and oqs-provider. None of the steps needs deep tricks; what they need is discipline about order.
Step 1: Preserve the Scene Completely
The moment an error appears, do not touch anything. Save three things verbatim: the full command you ran (including all flags and the environment variables in effect), the build tool’s complete output log, and the exit code. In practice, re-run once with output captured to files:
cmake -S . -B build -GNinja 2>&1 | tee configure.log
ninja -C build 2>&1 | tee build.log; echo "exit=$?"
Why completeness matters: build logs run to thousands of lines, the terminal scrollback shows only the tail, and the true first error usually sits somewhere in the middle; without the complete log, every later analysis rests on partial information. Record the environment versions of the moment alongside (compiler, CMake, key dependency versions), because the answer to “it built yesterday and fails today” usually hides in some version change. A preserved scene has a second use: when you ask the community or a colleague for help, this material is the entire basis of the request — without it, rounds of clarification questions burn everyone’s time.
Step 2: Read the Log from the First Error
The reading discipline has one rule: find the first error, not the last. A build is a pipeline; one step’s failure makes dozens of later steps fail in cascade, and the errors at the tail of the log are mostly echoes. Locate it like this: grep -n "error" build.log | head finds the line number of the first error; then read thirty lines around it in both directions and establish whether it is a compile error, a link error or a missing tool. If the information is insufficient, re-run in verbose mode: ninja -v prints every compile command actually executed, and make VERBOSE=1 does the same for Make projects — with the commands laid bare, which compiler was used, which include paths, which libraries were linked becomes obvious at a glance, and nine out of ten “wrong path” problems show themselves here. For configure-stage failures, look at CMake’s output and build/CMakeCache.txt: the cache records the actual probed value of every item, and comparing it against expectations line by line is how you distinguish “the setting never took effect” from “it took effect with the wrong value”.
Step 3: Narrow the Scope by Bisection
Once the error’s nature is established, cut the scope down with bisection, in three directions, ordered by suspicion. Version bisection: if the component built successfully before, use git bisect over the commit history — mark one known-good old commit and the current bad one, and Git checks out midpoints for you to test round by round; a dozen or so rounds lock onto the commit that introduced the problem, far more efficient than rolling back day by day. Configuration bisection: cut the build options in half, restore defaults for one half and keep the other, build once and see whether the error persists, and repeat until the conflicting option combination is isolated — the right tool for “all defaults build fine, my options break it”. Dependency bisection: when a link or runtime error points at a library, swap dependency versions back to a known-good set one at a time, or rebuild in a clean container with a minimal dependency set, and confirm which dependency the problem follows. The common discipline across all three: change exactly one dimension per round and record the result; changing several dimensions from memory degrades bisection into random search by your own hand.
A Dimension Often Missed: Incremental State
Before bisecting, exclude one class of fake failure: incremental-state contamination. A build directory holding a stale cache, a half-installed dependency, leftover artifacts from an interrupted build — any of these makes “the same command, the same version” produce different results, with flaky errors that change between runs. The exclusion test is embarrassingly cheap and constantly skipped: start over from a clean state — delete the build directory and reconfigure, or build once in a brand-new container or VM. If the clean state passes, the problem is not in the code but in your machine’s history, and what you investigate next is state, not source; if the clean state fails identically, formal bisection is warranted. Placing this step between steps two and three saves large amounts of time otherwise spent bisecting phantom problems. It also explains why “it works on my machine” carries no weight: a conclusion never verified from a clean state is a status report, not a fact.
Step 4: Converge on a Minimal Reproduction
Once the scope is narrow enough, extract the problem from the original project: create an empty directory and write the smallest source file and build script that still triggers the error — one header include, one linker flag, one call site, whatever the minimum turns out to be. A minimal reproduction pays off three ways: it proves you actually understand the trigger (if it does not reproduce, the localization is not yet accurate); it removes every other factor of the original project, so fixes can be verified directly; and it is the most persuasive material in a report to upstream maintainers, who can reproduce the problem in minutes — such reports get a completely different priority. If during reduction the minimal case stops failing, a hidden dependency remains in the trigger conditions: return to step three and keep bisecting rather than forcing the case. If the problem is finally confirmed to live in the upstream component itself, package the report in the order “versions, command, minimal reproduction, complete log” — reports in that shape usually get substantive responses.
Wrapping Up
Compress the procedure into a mnemonic: preserve the scene, read the first error, bisect the scope down, let a minimal reproduction settle it. Its reach goes far beyond build problems — runtime anomalies, performance regressions and environment drift all fit the same skeleton. Keep this article next to your lab notebook and deliberately walk the procedure the first few times; afterwards it becomes a habit that needs no reminding. Build failures stop being a matter of luck and become a matter of process.
Tags: Debugging MethodBuildsBisectionMinimal Reproduction