Keywords: Nachos | Cross-compilation | 32-bit libraries | Ubuntu | GCC
Abstract: This paper provides an in-depth analysis of the "gnu/stubs-32.h: No such file or directory" error encountered during Nachos operating system source code compilation on Ubuntu systems. Starting from cross-compilation environment configuration, it explores the root cause of missing 32-bit libraries and offers comprehensive solutions for various Linux distributions. Through systematic environment variable configuration and dependency package installation guidance, developers can quickly resolve such compilation errors and ensure successful Nachos project building.
Problem Background and Error Analysis
In operating system course practices, Nachos (Not Another Completely Heuristic Operating System) as a classic teaching operating system often requires cross-compilation on different architectures. Users encountered a critical compilation error when compiling Nachos source code on Ubuntu 11.04 system: /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.
Root Cause Analysis
The essence of this error lies in the absence of 32-bit C library development files. When using MIPS cross-compiler to build 32-bit target code, the compiler needs access to corresponding 32-bit header files and library files. In 64-bit Linux systems, the default installation typically includes 64-bit version development libraries, while 32-bit compatibility libraries require separate installation.
Specifically, the stubs-32.h file is a stub definition file in GNU C Library (glibc) for 32-bit architectures, containing macro definitions and function declarations specific to 32-bit environments. The absence of this file prevents the preprocessor from completing header file inclusion, leading to compilation failure.
Solution: Cross-Distribution Dependency Package Installation
Depending on different Linux distribution package management systems, corresponding 32-bit development libraries need to be installed:
Ubuntu/Debian Series
In Ubuntu systems, execute the following command to install 32-bit C library development package:
sudo apt-get install libc6-dev-i386
Red Hat/CentOS Series
For Red Hat family distributions, package names vary:
- CentOS 5.8:
sudo yum install glibc-devel.i386 - CentOS 6/7:
sudo yum install glibc-devel.i686
Other Distributions
- openSUSE/SLES:
sudo zypper in glibc-devel-32bit - Gentoo:
sudo emerge -1a sys-libs/glibc - Arch Linux:
sudo pacman -S lib32-glibc
Ubuntu 12.04 Special Configuration
In Ubuntu 12.04 and later versions, due to file path changes, additional environment variable settings are required:
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)
These environment variables ensure the compiler can correctly locate the non-standard installation locations of 32-bit libraries and header files.
C++ Compilation Support
If the project includes C++ code, 32-bit C++ standard library installation may also be required. When encountering link errors /usr/bin/ld: cannot find -lstdc++:
- Ubuntu:
sudo apt-get install g++-multilib - CentOS 5:
sudo yum install libstdc++-devel.i386 - CentOS 6:
sudo yum install libstdc++-devel.i686
Verification and Testing
After installation completion, rerun the make command to compile Nachos source code. If configured correctly, the compilation process should complete successfully. Generated object files can be checked and binary file architecture verified using the file command:
file nachos
The output should display a MIPS architecture 32-bit executable file.
Summary and Best Practices
Cross-compilation environment configuration is a common challenge in operating system development. By systematically installing correct development libraries and configuring environment variables, architecture compatibility issues can be effectively resolved. It is recommended to pre-check and install all necessary 32-bit development toolchains before starting cross-compilation projects to avoid compilation interruptions.