How to Generate autoconf.h in Linux Kernel Source Build: Missing Header File Fix


13 views

The include/generated/autoconf.h file is a critical header generated during Linux kernel compilation. It contains all configuration options from your .config file translated into C preprocessor macros. Many kernel modules and drivers depend on this file for conditional compilation.

When you extract kernel sources from RPM packages, the autoconf.h file won't exist because:

  • It's generated during the build process
  • SRPMs typically contain pristine source without build artifacts
  • The file is architecture-specific and generated per configuration

Here's the correct sequence to generate autoconf.h:

# Copy your existing config
cp /boot/config-$(uname -r) .config

# Prepare the build environment
make oldconfig

# Generate the header (without full compilation)
make prepare

# Alternatively, for a complete verification
make modules_prepare

If you still don't see autoconf.h after running these commands:

  1. Verify you're using the exact same kernel version as your running system
  2. Check the output directory: ls -l include/generated/autoconf.h
  3. Try cleaning first: make clean then make prepare

If you only need autoconf.h for module compilation:

# Install kernel-devel package (RedHat/CentOS)
sudo yum install kernel-devel-$(uname -r)

# The header will be at:
# /usr/src/kernels/$(uname -r)/include/generated/autoconf.h

For cross-compilation scenarios, specify the architecture:

make ARCH=arm64 oldconfig prepare

The autoconf.h file is a critical header generated during the Linux kernel build process. It contains configuration-dependent macros that determine which kernel features are enabled. Many kernel modules and drivers depend on this file for successful compilation.

# Example of typical autoconf.h content:
#define CONFIG_SMP 1
#define CONFIG_MODULES 1
#define CONFIG_HIGHMEM 1

When you extract kernel sources from RPM packages, autoconf.h won't exist because:

  • It's generated during the build process
  • SRPMs contain pristine sources before configuration
  • The file is architecture and configuration specific

While a complete kernel build would generate autoconf.h, you can create it with minimal steps:

# Copy your running kernel's config
cp /boot/config-$(uname -r) .config

# Prepare the build environment
make oldconfig
make prepare

# Verify the file exists
ls -l include/generated/autoconf.h

For cross-compilation or custom configurations:

# For ARM cross-compilation example
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make defconfig
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make prepare

# Using menuconfig for custom options
make menuconfig
make prepare

If autoconf.h still doesn't appear:

  • Verify kernel source version matches your running kernel
  • Check filesystem permissions in the source directory
  • Ensure all build dependencies are installed (make, gcc, etc.)
  • Try cleaning first: make mrproper

If you only need specific configuration values:

# Extract config from running kernel
zcat /proc/config.gz > .config

# Or check existing values
grep CONFIG_ /boot/config-$(uname -r)