我在为 QEMU 编译路由器内核时遇到问题。我让路由器在使用 OpenWRT 内核的 QEMU 中工作,但网络无法工作。这就是为什么我要编译原始内核。
以下命令是(主)Makefile 间接执行的有问题的命令。我说间接是因为它甚至没有明确选择执行配置脚本,它只是选择这样做,因为它位于编译内核所需的下载包的目录中。
PATH=/home/debian/build-new/host/bin:/home/debian/build-new/host/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/游戏:/usr/games AR="/usr/bin/ar" AS="/usr/bin/as" LD="/usr/bin/ld" NM="/usr/bin/nm" CC="/ home/debian/build-new/host/usr/bin/ccache /usr/bin/gcc" GCC="/home/debian/build-new/host/usr/bin/ccache /usr/bin/gcc" CXX= “/home/debian/build-new/host/usr/bin/ccache /usr/bin/g++” CPP="/usr/bin/cpp" CPPFLAGS="-I/home/debian/build-new/host/ usr/include" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" CXXFLAGS="-O2 -I/home/debian/build-new/host/usr/include" LDFLAGS= “-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/lib -Wl,-rpath,/home/debian/build-new/host/usr/ lib" PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG="/home/debian/build-new/host/usr/bin/pkg-config" PKG_CONFIG_SYSROOT_DIR="/" PKG_CONFIG_LIBDIR="/home/debian/build-new/host/usr /lib/pkgconfig:/home/debian/build-new/host/usr/share/pkgconfig" PERLLIB="/home/debian/build-new/host/usr/lib/perl" LD_LIBRARY_PATH="/home/debian/ build-new/host/usr/lib:" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" LDFLAGS="-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/lib -Wl,-rpath,/home/debian/build-new/host/usr/lib" CC="/usr/bin/gcc" ./configure --prefix="/home/debian/build-new/host/usr" --sysconfdir="/home/debian/build-new/host/etc" --enable-shared --disable-static --disable- gtk-doc --disable-doc --disable-docs --disable-documentation --with-xmlto=no --with-fop=no ccache_cv_zlib_1_2_3=no
中断命令的标志是 LDFLAGS。
LD="/usr/bin/ld" LDFLAGS="-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/lib -Wl,-rpath,/ home/debian/build-new/host/usr/lib" LDFLAGS="-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/lib -Wl, -rpath,/home/debian/build-new/host/usr/lib"
运行命令的输出是:
debian@debian-i686:~/build-new/build/host-ccache-3.1.8$ PATH=/home/debian/build-new/host/bin:/home/debian/build-new/host/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games AR="/usr/bin/ar" AS="/usr/bin/as" LD="/usr/bin/ld" NM="/usr/bin/nm" CC="/home/debian/build-new/host/usr/bin/ccache /usr/bin/gcc" GCC="/home/debian/build-new/host/usr/bin/ccache /usr/bin/gcc" CXX="/home/debian/build-new/host/usr/bin/ccache /usr/bin/g++" CPP="/usr/bin/cpp" CPPFLAGS="-I/home/debian/build-new/host/usr/include" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" CXXFLAGS="-O2 -I/home/debian/build-new/host/usr/include" LDFLAGS="-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/lib -Wl,-rpath,/home/debian/build-new/host/usr/lib" PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG="/home/debian/build-new/host/usr/bin/pkg-config" PKG_CONFIG_SYSROOT_DIR="/" PKG_CONFIG_LIBDIR="/home/debian/build-new/host/usr/lib/pkgconfig:/home/debian/build-new/host/usr/share/pkgconfig" PERLLIB="/home/debian/build-new/host/usr/lib/perl" LD_LIBRARY_PATH="/home/debian/build-new/host/usr/lib:" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" LDFLAGS="-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/lib -Wl,-rpath,/home/debian/build-new/host/usr/lib" CC="/usr/bin/gcc" ./configure --prefix="/home/debian/build-new/host/usr" --sysconfdir="/home/debian/build-new/host/etc" --enable-shared --disable-static --disable-gtk-doc --disable-doc --disable-docs --disable-documentation --with-xmlto=no --with-fop=no ccache_cv_zlib_1_2_3=no
configure: WARNING: unrecognized options: --enable-shared, --disable-static, --disable-gtk-doc, --disable-doc, --disable-docs, --disable-documentation, --with-xmlto, --with-fop
configure: Configuring ccache
checking for gcc... /usr/bin/gcc
checking whether the C compiler works... no
configure: error: in `/home/debian/build-new/build/host-ccache-3.1.8':
configure: error: C compiler cannot create executables
See `config.log' for more details
仅删除 LDFLAGS 可以修复特定错误,但稍后我又遇到另一个错误。
debian@debian-i686:~/build-new/build/host-ccache-3.1.8$ PATH=/home/debian/build-new/host/bin:/home/debian/build-new/host/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games AR="/usr/bin/ar" AS="/usr/bin/as" LD="/usr/bin/ld" NM="/usr/bin/nm" CC="/home/debian/build-new/host/usr/bin/ccache /usr/bin/gcc" GCC="/home/debian/build-new/host/usr/bin/ccache /usr/bin/gcc" CXX="/home/debian/build-new/host/usr/bin/ccache /usr/bin/g++" CPP="/usr/bin/cpp" CPPFLAGS="-I/home/debian/build-new/host/usr/include" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" CXXFLAGS="-O2 -I/home/debian/build-new/host/usr/include" PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG="/home/debian/build-new/host/usr/bin/pkg-config" PKG_CONFIG_SYSROOT_DIR="/" PKG_CONFIG_LIBDIR="/home/debian/build-new/host/usr/lib/pkgconfig:/home/debian/build-new/host/usr/share/pkgconfig" PERLLIB="/home/debian/build-new/host/usr/lib/perl" LD_LIBRARY_PATH="/home/debian/build-new/host/usr/lib:" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" CC="/usr/bin/gcc" ./configure --prefix="/home/debian/build-new/host/usr" --sysconfdir="/home/debian/build-new/host/etc" --enable-shared --disable-static --disable-gtk-doc --disable-doc --disable-docs --disable-documentation --with-xmlto=no --with-fop=no ccache_cv_zlib_1_2_3=no
configure: WARNING: unrecognized options: --enable-shared, --disable-static, --disable-gtk-doc, --disable-doc, --disable-docs, --disable-documentation, --with-xmlto, --with-fop
configure: Configuring ccache
checking for gcc... /usr/bin/gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/home/debian/build-new/build/host-ccache-3.1.8':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
删除所有标志(以获取下面的命令)可以使配置脚本完美运行。
./configure --prefix="/home/debian/build-new/host/usr" --sysconfdir="/home/debian/build-new/host/etc" --enable-shared --disable-static - -disable-gtk-doc --disable-doc --disable-docs --disable-documentation --with-xmlto=no --with-fop=no ccache_cv_zlib_1_2_3=no
配置脚本崩溃的原因是它试图找到文件path/to/lib/libc.so.0 和path/to/usr/lib/uclibc_nonshared.a。问题是,脚本试图在 /lib/ 和 /usr/lib/ 中找到这些库,即使 Makefile 明确设置了应该从哪里获取库。从 LDFLAGS 指向的位置手动符号链接库以使其链接到 /lib/ 和 /usr/lib/ 只会导致以下消息:
/usr/bin/ld: skipping incompatible /lib/libc.so.0 when searching for /lib/libc.so.0
/usr/bin/ld: cannot find /lib/libc.so.0
/usr/bin/ld: skipping incompatible /usr/lib/uclibc_nonshared.a when searching for /usr/lib/uclibc_nonshared.a
/usr/bin/ld: cannot find /usr/lib/uclibc_nonshared.a
此外,将 LD 标志设置为 并LD="/home/debian/build-new/host/usr/bin/mips-linux-ld"
不能解决问题。
如何让 Makefile 正确编译?我留下了一些日志和配置Github 的要点服务。
编辑:
使用@filbranden 的提示我现在已经达到了获得如下输出结果的程度:
/home/debian/build-new/toolchain/gcc-4.7.3-intermediate/./gcc/xgcc -B/home/debian/build-new/toolchain/gcc-4.7.3-intermediate/./gcc/ - B/home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/bin/ -B/home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/lib/ - isystem /home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/include -isystem /home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/sys-include - g -Os -O2 -g -Os -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fPIC -I。 -我。 -I../.././gcc -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc -I/home/debian/build-new/toolchain/gcc-4.7.3/ libgcc/. -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc/../gcc -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc/../include -DHAVE_CC_TLS -o _fractHADI_s.o -MT _fractHADI_s.o -MD -MP -MF _fractHADI_s.dep -DSHARED -DL_fract -DFROM_HA -DTO_DI -c /home/debian/build-new/toolchain/gcc-4.7.3/libgcc/固定位.c
/home/debian/build-new/toolchain/gcc-4.7.3-intermediate/./gcc/xgcc -B/home/debian/build-new/toolchain/gcc-4.7.3-intermediate/./gcc/ - B/home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/bin/ -B/home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/lib/ - isystem /home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/include -isystem /home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/sys-include - g -Os -O2 -g -Os -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fPIC -I。 -我。 -I../.././gcc -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc -I/home/debian/build-new/toolchain/gcc-4.7.3/ libgcc/. -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc/../gcc -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc/../include -DHAVE_CC_TLS -o _fractHATI_s.o -MT _fractHATI_s.o -MD -MP -MF _fractHATI_s.dep -DSHARED -DL_fract -DFROM_HA -DTO_TI -c /home/debian/build-new/toolchain/gcc-4.7.3/libgcc/固定位.c
/home/debian/build-new/toolchain/gcc-4.7.3-intermediate/./gcc/xgcc -B/home/debian/build-new/toolchain/gcc-4.7.3-intermediate/./gcc/ - B/home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/bin/ -B/home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/lib/ - isystem /home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/include -isystem /home/debian/build-new/host/usr/mips-buildroot-linux-uclibc/sys-include - g -Os -O2 -g -Os -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fPIC -I。 -我。 -I../.././gcc -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc -I/home/debian/build-new/toolchain/gcc-4.7.3/ libgcc/. -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc/../gcc -I/home/debian/build-new/toolchain/gcc-4.7.3/libgcc/../include -DHAVE_CC_TLS -o _fractHASF_s.o -MT _fractHASF_s.o -MD -MP -MF _fractHASF_s.dep -DSHARED -DL_fract -DFROM_HA -DTO_SF -c /home/debian/build-new/toolchain/gcc-4.7.3/libgcc/固定位.c
此编译现在已经运行了 17-18 小时(并且没有崩溃或执行任何其他操作来表明可能发生了错误)。它仍然在固定位.c 上工作,这似乎有点奇怪,但这也许是正常的?
答案1
使用@filbranden 的评论,我能够为我的路由器编译内核(还有更多错误需要解决,但这不是这个问题的范围)。
我留下了一个日志和我编译内核的配置Github 要点(新日志和配置)。配置被破坏,直到实际编译linux阶段才会显现出来,但这些解决方案很简单。
我运行以下命令来编译内核:
make menuconfig O=~/build-new/
RANLIB="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-ranlib" READELF="/home/debian/new-kernel/萨基姆/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-readelf" OBJDUMP="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3- 3/usr/bin/mips-linux-uclibc-objdump" AR="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc- ar" AS="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-as" LD="/home/debian/new-内核/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-gcc" NM="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2。 3-3/usr/bin/mips-linux-uclibc-nm" CC="/home/debian/bin-new/ccache-3.1.8/ccache /home/debian/new-kernel/sagem/uclibc-crosstools- gcc-4.2.3-3/usr/bin/mips-linux-uclibc-gcc" GCC="/home/debian/bin-new/ccache-3.1.8/ccache /home/debian/new-kernel/sagem/ uclibc-crosstools-gcc-4.2.3-3/usr/bin/gcc" CXX="/home/debian/bin-new/ccache-3.1.8/ccache /home/debian/new-kernel/sagem/uclibc- crosstools-gcc-4.2.3-3/usr/bin/g++" CPP="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux- uclibc-cpp" CPPFLAGS="-I/home/debian/build-new/host/usr/include" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" CXXFLAGS="- O2 -I/home/debian/build-new/host/usr/include" LDFLAGS="-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/ lib" make autoconf O=~/build-new/
RANLIB="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-ranlib" READELF="/home/debian/new-kernel/萨基姆/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-readelf" OBJDUMP="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3- 3/usr/bin/mips-linux-uclibc-objdump" AR="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc- ar" AS="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-as" LD="/home/debian/new-内核/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-gcc" NM="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2。 3-3/usr/bin/mips-linux-uclibc-nm" CC="/home/debian/bin-new/ccache-3.1.8/ccache /home/debian/new-kernel/sagem/uclibc-crosstools- gcc-4.2.3-3/usr/bin/mips-linux-uclibc-gcc" GCC="/home/debian/bin-new/ccache-3.1.8/ccache /home/debian/new-kernel/sagem/ uclibc-crosstools-gcc-4.2.3-3/usr/bin/gcc" CXX="/home/debian/bin-new/ccache-3.1.8/ccache /home/debian/new-kernel/sagem/uclibc- crosstools-gcc-4.2.3-3/usr/bin/g++" CPP="/home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux- uclibc-cpp" CPPFLAGS="-I/home/debian/build-new/host/usr/include" CFLAGS="-O2 -I/home/debian/build-new/host/usr/include" CXXFLAGS="- O2 -I/home/debian/build-new/host/usr/include" LDFLAGS="-L/home/debian/build-new/host/lib -L/home/debian/build-new/host/usr/ lib -Wl,-rpath,/home/debian/build-new/host/usr/lib" make O=~/build-new/
鉴于以下错误,在运行 make 命令之前,我仍然必须符号链接一些二进制文件:
Checking for C compiler ... none found
ERROR: no C compiler found
Checking for linker ... '/home/debian/build-new/host/usr/bin/mips-buildroot-linux-uclibc-gcc' not found (user)
ERROR: no linker found
Checking for ar ... /home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-ar ()
Checking for ranlib ... /home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-ranlib ()
Checking for readelf ... none found
ERROR: no readelf found
Checking for objdump ... /home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-objdump ()
我符号链接的二进制文件如下。我在那些我认为符号链接无关紧要的符号前面放了一个井号(因为路径永远无法从 make 命令的前缀中设置)。
mkdir -p /home/debian/build-new/host/usr/bin/
cp -r /home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/* /home/debian/build-new/host/usr/bin/
cd /home/debian/build-new/host/usr/bin/
ln -s mips-linux-uclibc-gcc mips-buildroot-linux-uclibc-gcc
#ln -s /home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-ranlib mips-buildroot-linux-uclibc-ranlib
#ln -s /home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-readelf mips-buildroot-linux-uclibc-readelf
#ln -s /home/debian/new-kernel/sagem/uclibc-crosstools-gcc-4.2.3-3/usr/bin/mips-linux-uclibc-objdump mips-buildroot-linux-uclibc-objdump
当涉及到构建内核本身时,这里的配置和命令仍然被破坏,但它们的功能足以克服此错误的阶段。今天早上我成功编译了内核(花了超过 24 小时的纯编译时间),但是在 QEMU 中启动它并挂载我从路由器复制的文件系统后,我开始意识到我选择了错误的字节顺序(我选择了通过选择大端而非小端,LSB 而非 MSB)。
否则,我已经使用@filbranden 的帮助成功编译了内核。