Senger CodeLab 🚀

Error gnustubs-32h No such file or directory while compiling Nachos source code

September 29, 2026

Error gnustubs-32h No such file or directory while compiling Nachos source code

Embarking on the journey of compiling the Nachos operating system source code is a classic rite of passage for many computer science students, offering invaluable insights into how an OS functions at a fundamental level. However, this educational experience often comes with its own set of hurdles, and one of the most frequently encountered challenges is the cryptic error: “gnu/stubs-32.h: No such file or directory.” This message typically signals a mismatch in your development environment, specifically concerning the necessary 32-bit compatibility libraries on a modern 64-bit Linux system. This guide will meticulously walk you through understanding the root cause of this error and provide a comprehensive, actionable solution to get your Nachos compilation back on track, ensuring a smooth learning curve.

Understanding the “gnu/stubs-32.h” Error in Nachos Compilation

The error “gnu/stubs-32.h: No such file or directory” is a strong indicator that your system lacks the essential 32-bit development libraries required by the Nachos source code. Nachos, originally designed in an era when 32-bit systems were prevalent, expects a compilation environment that can produce 32-bit executables. Modern Linux distributions, however, are predominantly 64-bit, and while they can run 32-bit applications, they don’t always include the 32-bit development headers and libraries by default. This discrepancy leads to the GCC compiler failing to locate critical files like gnu/stubs-32.h, which are part of the standard C library’s 32-bit headers.

Specifically, this issue arises because the Nachos build process often uses cross-compilation tools or simply targets a 32-bit architecture. When the compiler attempts to link or pre-process, it searches for system headers specific to the target architecture. On a 64-bit system without multilib support enabled or the necessary 32-bit development packages installed, these headers are simply absent. This is not a flaw in Nachos itself, but rather a configuration challenge stemming from the evolution of operating system architectures. Resolving it involves bridging the gap between a 64-bit host system and the 32-bit requirements of Nachos, ensuring all the right system libraries are present.

According to a 2022 survey by the Linux Foundation, over 90% of active Linux users now run 64-bit distributions. This statistic underscores why encountering 32-bit compatibility issues is so common when working with legacy projects like Nachos. The compiler, in its attempt to satisfy dependencies for the 32-bit target, correctly reports the absence of this crucial header, preventing further progress. Understanding this foundational incompatibility is the first step toward a successful resolution, paving the way for a properly configured build environment.

Setting Up Your Nachos Build Environment for 32-bit Compatibility

Before diving into specific solutions, it’s crucial to prepare your build environment to handle 32-bit compilation effectively. This involves ensuring your system can install and utilize libraries from multiple architectures, a concept known as multilib. Most modern Linux distributions support multilib, but the necessary development packages are often not installed by default. Without these, the GCC compiler will continue to report the “gnu/stubs-32.h: No such file or directory” error, as it simply won’t find the required 32-bit header files.

The primary LSI keyword here is multilib support, which is the cornerstone for solving this particular error. It allows your 64-bit system to house and manage both 64-bit and 32-bit versions of libraries. For instance, on Debian/Ubuntu-based systems, enabling multilib involves adding the ‘i386’ architecture and then updating your package lists. Fedora/CentOS systems handle this slightly differently, often through specific package group installations. Once enabled, you can then install the specific 32-bit development packages that Nachos depends on, providing the compiler with the necessary header files.

Beyond multilib, you also need the standard development tools. This includes the GNU Compiler Collection (GCC), Make, and potentially other build utilities. Ensure these are up-to-date and correctly configured for your environment. A common mistake is to overlook the specific 32-bit versions of these tools or their associated libraries. For example, installing build-essential on Debian/Ubuntu is a good start, but it must be complemented by 32-bit versions of core libraries. A robust build environment is your strongest ally when tackling legacy codebases like Nachos.

Infographic: Visualizing the 64-bit Host vs. 32-bit Target Problem
Step-by-Step Solution to Resolve the "gnu/stubs-32.h" Error -----------------------------------------------------------

Resolving the “gnu/stubs-32.h: No such file or directory” error primarily involves installing the correct 32-bit development libraries on your 64-bit Linux system. This typically requires enabling multi-architecture support and then installing specific packages. The steps may vary slightly depending on your Linux distribution, but the underlying principle remains the same: provide the compiler with the necessary 32-bit system libraries. This process bridges the gap between your modern 64-bit operating system and the 32-bit compilation requirements of the Nachos source code.

For most Debian/Ubuntu-based systems, the solution involves a few straightforward commands. First, you need to add the i386 architecture to your system’s capabilities. Then, you update your package lists to recognize the new architecture. Finally, you install the critical 32-bit C standard library development package. This package contains the elusive gnu/stubs-32.h and other necessary headers that the Nachos build system is searching for. Fedora and Arch Linux users will follow similar logic but use their respective package managers and package names.

Once these libraries are installed, you should be able to compile Nachos without encountering this specific header file error. It’s a testament to the flexibility of modern Linux that it can accommodate such legacy requirements with relative ease, provided you know which packages to install. This approach ensures that your development tools can correctly locate all the dependencies for the 32-bit target architecture, allowing your Nachos compilation to proceed smoothly.

Here’s an ordered list of steps for common Linux distributions:

  1. **For Debian/Ubuntu-based systems:**First, enable the i386 architecture:

    sudo dpkg --add-architecture i386
    

    Next, update your package list:

    sudo apt update
    

    Finally, install the 32-bit development library for the C standard library:

    sudo apt install libc6-dev-i386
    

    You might also need other build essentials if not already installed:

    sudo apt install build-essential gcc-multilib g++-multilib
    
  2. **For Fedora/CentOS-based systems:**Install the 32-bit C standard library development package and GCC multilib support:

    sudo dnf install glibc-devel.i686 libgcc.i686 libstdc++-devel.i686
    

    For older CentOS/RHEL versions using yum:

    sudo yum install glibc-devel.i686 libgcc.i686 libstdc++-devel.i686
    
  3. **For Arch Linux:**Ensure the multilib repository is enabled in /etc/pacman.conf by uncommenting the relevant lines. Then sync and install:

    sudo pacman -Sy
    
    sudo pacman -S lib32-glibc lib32-gcc-libs
    
  4. **After installation:**Navigate to your Nachos source directory and try compiling again:

    make
    

    This should now proceed without the “gnu/stubs-32.h: No such file or directory” error.

Common Pitfalls and Advanced Troubleshooting for Nachos Compilation

While installing libc6-dev-i386 or its equivalent often resolves the “gnu/stubs-32.h” error, other issues can still arise during Question & Answer :

I am trying to install Nachos on my laptop and I have Ubuntu 11.04 on the laptop.

The code is in C and so to build it I assume I will need cross compiler. This is where my problem is. I downloaded the source code of the MIPS cross compiler using the command

wget http://mll.csie.ntu.edu.tw/course/os_f08/assignment/mips-decstation.linux-xgcc.gz 

and I unzipped it using

tar zxvf mips-decstation.linux-xgcc.gz 

This is okay, but when I try to build the source code of the nachos os, using make, I get this error -

/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory compilation terminated. make: *** [bitmap.o] Error 1 

I am trying to follow the instructions given over here - http://mll.csie.ntu.edu.tw/course/os_f08/217.htm and everything is working fine except when I try to use make.

You’re missing the 32 bit libc dev package:

On Ubuntu it’s called libc6-dev-i386 - do sudo apt-get install libc6-dev-i386. See below for extra instructions for Ubuntu 12.04.

On Red Hat distros, the package name is glibc-devel.i686 (Thanks to David Gardner’s comment).

On CentOS 5.8, the package name is glibc-devel.i386 (Thanks to JimKleck’s comment).

On CentOS 6 / 7, the package name is glibc-devel.i686.

On SLES it’s called glibc-devel-32bit - do zypper in glibc-devel-32bit.

On Gentoo it’s called sys-libs/glibc - do emerge -1a sys-libs/gcc [source] (Note : One may use equery to confirm this is correct; do equery belongs belongs /usr/include/gnu/stubs-32.h)

On ArchLinux, the package name is lib32-glibc - do pacman -S lib32-glibc.


Are you using Ubuntu 12.04? There is a known problem that puts the files in a non standard location. You’ll also need to do:

export LIBRARY_PATH=/usr/lib/$(gcc -print-multiarch) export C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch) export CPLUS_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch) 

somewhere before you build (say in your .bashrc).


If you are also compiling C++ code, you will also need the 32 bit stdc++ library. If you see this warning:

…. /usr/bin/ld: cannot find -lstdc++ ….

On Ubuntu you will need to do sudo apt-get install g++-multilib

On CentOS 5 you will need to do yum install libstdc++-devel.i386

On CentOS 6 you will need to do yum install libstdc++-devel.i686

Please feel free to edit in the packages for other systems.