无网络无apt环境下Ubuntu Server 16.04编译GCC-5.4.0遇configure失败
Let's walk through resolving this step by step—since you're stuck without network access, can't use apt to install a compiler, and need GCC to recompile your kernel for that Ethernet NIC issue, here's how to get past the ./configure failure:
1. First, Ensure You Have Basic Build Tools
GCC itself requires some foundational tools to compile, even if you don't have a full C compiler yet. Let's check if they're present:
- Run
which makeandwhich ld—if these return paths, you're good on make and the linker. - If not, grab these packages from your Ubuntu Server 16.04 installation ISO (copy the ISO to your USB drive and mount it on the server):
# Mount the ISO (replace /path/to/your/iso with the actual path) mount /path/to/ubuntu-16.04-server-amd64.iso /mnt # Navigate to the pool of core packages cd /mnt/pool/main # Install make, binutils, and libc6-dev (install in this order to avoid dependency issues) dpkg -i libc6-dev_*.deb binutils_*.deb make_*.deb
2. Use an Out-of-Tree Build Directory (Critical for GCC)
GCC does not support in-tree configuration (running ./configure directly in the source root)—this is almost certainly one of the reasons your configure failed. Do this instead:
# Create a separate build directory outside the GCC source folder mkdir gcc-build && cd gcc-build # Run the configure script from the build directory, with sensible flags ../gcc-5.4.0/configure --prefix=/usr/local/gcc-5.4 --enable-languages=c,c++ --disable-multilib
Let's break down the flags:
--prefix=/usr/local/gcc-5.4: Sets where the compiled GCC will be installed (keeps it separate from system tools)--enable-languages=c,c++: Only compiles C and C++ support (cuts down on compile time and dependencies)--disable-multilib: Disables 32-bit library support if you're on a 64-bit system (avoids common configuration errors)
3. Resolve Missing Math Library Dependencies
If configure still fails, check the config.log file in your build directory—you'll likely see errors about missing GMP, MPFR, or MPC libraries (GCC relies on these for math operations). Since you have no network:
- Copy the source code for GMP, MPFR, and MPC to your server via USB (match versions compatible with GCC 5.4.0: GMP 6.x, MPFR 3.x, MPC 1.x)
- Extract each library into separate folders, then update your configure command to point to them:
../gcc-5.4.0/configure --prefix=/usr/local/gcc-5.4 --enable-languages=c,c++ --disable-multilib \ --with-gmp=/path/to/extracted/gmp \ --with-mpfr=/path/to/extracted/mpfr \ --with-mpc=/path/to/extracted/mpc
4. Compile and Install GCC
Once configure succeeds, compile with all available CPU cores to speed things up:
make -j$(nproc)
Then install the compiled GCC:
sudo make install
Finally, add the new GCC to your system PATH so it's usable:
export PATH=/usr/local/gcc-5.4/bin:$PATH # To make this permanent, add the line above to ~/.bashrc
After this, you'll have a working GCC compiler to recompile your kernel and fix that Ethernet NIC issue.
内容的提问来源于stack exchange,提问作者amateurece

