← Back to section · Tutorials & Labs

Building liboqs from Source: An Environment Troubleshooting Handbook

The common environment failures of a liboqs source build, class by class: missing or outdated toolchain pieces, OpenSSL headers and link paths, the dynamic-library cache, and Python bindings that cannot find the library — each with a locating command and a fix.

Published 22 November 2026 · 5 min read · PQ Frontier

Building liboqs from Source: An Environment Troubleshooting Handbook
AI-generated site artwork
Video explainer · Lab setup: build and troubleshoot

Building liboqs from source is the first gate in PQC experimentation, and the place where newcomers most often get stuck. The good news: the causes of failure are highly concentrated, and most of them are environment problems rather than defects in liboqs itself. This tutorial first establishes a standard build route, then dissects the failures class by class — each with symptoms, a locating command, and a fix. When you hit an error, do not search error strings one by one; first decide which class it belongs to.

The Standard Build Route: Establish a Baseline First

git clone https://github.com/open-quantum-safe/liboqs.git
cd liboqs
mkdir build && cd build
cmake -GNinja ..
ninja
sudo ninja install
sudo ldconfig

Every step of this route maps to a failure class: the cmake stage probes the compiler, OpenSSL and CPU capabilities, and configuration problems surface there; the ninja stage does the actual compilation and linking; ninja install places the library and headers under /usr/local; and the final ldconfig refreshes the dynamic-library cache — the step most often omitted from tutorials, and precisely the top cause of “installed but not found” errors afterwards. Always use a dedicated build subdirectory; if a configuration goes wrong you delete it and start over, instead of wrestling inside the source tree.

Class 1: Missing or Outdated Toolchain

Symptoms include cmake: command not found, CMake Error: CMake was unable to find a build program corresponding to "Ninja", and configure-stage complaints that the compiler does not meet requirements. Locating the problem is direct: run gcc --version, cmake --version and ninja --version one by one, and install whatever is missing. CMake versions deserve emphasis: the CMake shipped in some old distribution repositories is too dated to process the newer CMake syntax liboqs uses, and the resulting error usually points at some unrelated module. The fix is a newer CMake from the distribution’s newer repositories or the official CMake binary distribution — not editing liboqs’ CMakeLists. If the generator is missing you can temporarily fall back to Make (drop -GNinja and replace ninja with make) to validate the remaining steps, but a proper lab environment should have Ninja installed so command shapes match the official documentation.

Class 2: OpenSSL Headers and Linking

When the build is configured to reuse OpenSSL’s hash and symmetric implementations (with the OQS_USE_OPENSSL option enabled), CMake looks for OpenSSL during the configure stage. Typical errors are a missing openssl/evp.h or a configure summary reporting OpenSSL as not found. The most common cause is having only the OpenSSL runtime installed without the development package: on Debian / Ubuntu confirm libssl-dev is present; on Fedora the equivalent is openssl-devel. ls /usr/include/openssl/evp.h confirms in one second whether the header exists. A second scenario is several OpenSSL installations on one machine, with CMake finding the wrong one: pass cmake -DOPENSSL_ROOT_DIR=/path/to/openssl .. to name the root explicitly, and verify the version and path printed in the configure output. Do not work around this by changing the system default links — that plants a landmine for the whole machine.

Class 3: Installed Successfully, but the Library Is Not Found

Compilation and installation complete, yet import oqs or an example program fails with liboqs.so: cannot open shared object file — the most classic class of all. The reason is that liboqs installs into /usr/local/lib by default, and on some distributions the runtime linker’s cache does not include that directory, or the cache was never refreshed. Work through the fixes in order: run sudo ldconfig and confirm with ldconfig -p | grep liboqs; if it does not appear, check whether a file under /etc/ld.so.conf.d/ lists /usr/local/lib, add one if needed, and run ldconfig again; for a quick test, export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH and retry — if that works, the problem is confirmed to be the search path. The Python binding liboqs-python adds one more layer: it loads the C library dynamically at import time, so Python-side errors have the same root cause. Fix the path before suspecting the binding itself.

Class 4: Configuration Options and Algorithm Switches

liboqs offers many CMake options, for example -DOQS_ALGS_ENABLED=STD to build only standardized algorithms and shorten build times, or CMAKE_BUILD_TYPE=Release to guarantee optimization levels. Two failure modes recur. First, a misspelled variable name is silently ignored by CMake, the build completes with defaults, and your experiment unknowingly runs the wrong parameter set — the defense is a habit: after every configure run, read the configuration summary at the end of the CMake output and check the key options and algorithm counts. Second, changing options while reusing an old build directory lets the cache defeat the new settings — the defense is to delete the build directory and reconfigure on any configuration change. For performance comparisons, also confirm the build type is Release; numbers from a Debug build are worthless.

Class 5: Resource Exhaustion and Parallel Builds

The four classes above are all configuration and path problems; one more class is purely about resources. Ninja parallelizes to the CPU core count by default, and some liboqs translation units are memory-hungry; on a virtual machine with only 2–4 GB of RAM, a fully parallel build can exhaust memory, and the symptom is the compiler process being killed by the system — the log shows ninja: build stopped or a Killed compiler, looking like a random crash. Locate it by watching system memory state when the build dies, or simply re-run with ninja -j2 to limit parallelism: if it passes stably, the resource hypothesis is confirmed. Three grades of fix: giving the VM more memory is the thorough one; limiting parallelism is the cheapest, at the cost of slower builds; temporarily enlarging swap is an emergency measure, not a routine. This class has a confusing property: it depends on the machine’s load at the time, so the same code builds on one attempt and fails on the next — whenever a build is flaky, suspect resources before suspecting code. And if the compiler was swapped or system libraries were upgraded mid-way, a stale build directory cache produces the same flakiness; the handling principle is unchanged: delete the build directory and start again from the configure stage.

Wrapping Up

The five failure classes correspond to five checkpoints: toolchain versions, development packages and headers, the runtime library path, the configuration cache, and build resources. Turn the commands in this tutorial into a one-page cheat sheet in your lab notebook. Next time a build fails, spend five minutes classifying the failure before fixing it — that is much faster than blindly searching the last error line. A companion article on this site covers the systematic debugging methodology in general.

Tags: liboqsBuild TroubleshootingCMakeSource Build