我想使用预安装的mips交叉编译器(mips-linux-gnu-gcc)构建newlib库。编译器默认情况下链接glibc。

$ mips-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=mips-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/mips-linux-gnu/5/lto-wrapper
Target: mips-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.9' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr     --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-mips-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-mips-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-mips-cross --with-arch-directory=mips --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --enable-multiarch --disable-werror --enable-multilib --with-arch-32=mips32r2 --with-fp-32=xx --enable-targets=all --with-arch-64=mips64r2 --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=mips-linux-gnu --program-prefix=mips-linux-gnu- --includedir=/usr/mips-linux-gnu/include
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)


现在,我只想使用mips编译器来编译newlib库:
$ ../newlib-3.0.0.20180226/configure  --target=mips-linux-gnu --prefix=`pwd`
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... mips-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... no
checking for mawk... mawk
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether we are using the GNU C++ compiler... no
checking whether mips-linux-gnu-gcc accepts -g... no
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for isl 0.16, 0.15, or deprecated 0.14... no
recommended isl version is 0.16 or 0.15, the minimum required isl version 0.14 is deprecated
checking for isl 0.16 or 0.15... no
*** This configuration is not supported in the following subdirectories:
 target-newlib target-libgloss
(Any other directories should still work fine.)
checking for default BUILD_CONFIG...
checking for --enable-vtable-verify... no
checking for bison... bison -y
checking for bison... bison
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... no
checking for lex... no
checking for flex... no
checking for makeinfo... makeinfo
checking for expect... no
checking for runtest... no
checking for strip... strip
checking for windres... no
checking for windmc... no
checking for objcopy... objcopy
checking for objdump... objdump
checking for readelf... readelf
checking for mips-linux-gnu-cc... no
checking for mips-linux-gnu-gcc... mips-linux-gnu-gcc
checking for mips-linux-gnu-c++... no
checking for mips-linux-gnu-g++... no
checking for mips-linux-gnu-cxx... no
checking for mips-linux-gnu-gxx... no
checking for mips-linux-gnu-gcc... mips-linux-gnu-gcc
checking for mips-linux-gnu-gcj... no
checking for mips-linux-gnu-gfortran... no
checking for mips-linux-gnu-gccgo... no
checking for mips-linux-gnu-ar... mips-linux-gnu-ar
checking for mips-linux-gnu-as... mips-linux-gnu-as
checking for mips-linux-gnu-dlltool... no
checking for mips-linux-gnu-ld... mips-linux-gnu-ld
checking for mips-linux-gnu-lipo... no
checking for mips-linux-gnu-nm... mips-linux-gnu-nm
checking for mips-linux-gnu-objcopy... mips-linux-gnu-objcopy
checking for mips-linux-gnu-objdump... mips-linux-gnu-objdump
checking for mips-linux-gnu-ranlib... mips-linux-gnu-ranlib
checking for mips-linux-gnu-readelf... mips-linux-gnu-readelf
checking for mips-linux-gnu-strip... mips-linux-gnu-strip
checking for mips-linux-gnu-windres... no
checking for mips-linux-gnu-windmc... no
checking where to find the target ar... pre-installed
checking where to find the target as... pre-installed
checking where to find the target cc... pre-installed
checking where to find the target c++... pre-installed
checking where to find the target c++ for libstdc++... pre-installed
checking where to find the target dlltool... pre-installed
checking where to find the target gcc... pre-installed
checking where to find the target gcj... pre-installed
checking where to find the target gfortran... pre-installed
checking where to find the target gccgo... pre-installed
checking where to find the target ld... pre-installed
checking where to find the target lipo... pre-installed
checking where to find the target nm... pre-installed
checking where to find the target objcopy... pre-installed
checking where to find the target objdump... pre-installed
checking where to find the target ranlib... pre-installed
checking where to find the target readelf... pre-installed
checking where to find the target strip... pre-installed
checking where to find the target windres... pre-installed
checking where to find the target windmc... pre-installed
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile

但是当我随后运行make时,什么也没有发生:
$ make
make[1]: Entering directory '/home/qfi/newlib-build'
mkdir -p -- ./etc
Configuring in ./etc
configure: creating cache ./config.cache
checking for a BSD-compatible install... /usr/bin/install -c
configure: updating cache ./config.cache
configure: creating ./config.status
config.status: creating Makefile
make[2]: Entering directory '/home/qfi/newlib-build/etc'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/qfi/newlib-build/etc'
make[1]: Nothing to be done for 'all-target'.
make[1]: Leaving directory '/home/qfi/newlib-build'

当我将CC设置为mips-linux-gnu-gcc时,make抱怨缺少--host选项。
我的构建步骤有问题吗?

起初,这项任务对我来说似乎很简单,但现在我对如何使其工作一无所知。

最佳答案

我认为问题在此处显示在newlib配置中:

*** This configuration is not supported in the following subdirectories:
 target-newlib target-libgloss

这意味着它实际上不会为目标构建newlib!

我认为问题在于mips-linux-gnu并不是newlib的有意义的目标,因为这意味着使用glibc,而newlib不想依赖glibc。

我可能是错的,但是我认为您需要像mips-elf交叉编译器之类的东西来构建newlib(我不确定目标三元组,所以检查一下!)。因此,首先使用--target=mips-elf --without-headers --prefix=$PATH_WHERE_YOU_WANT_THE_CROSS_COMPILER配置GCC并仅使用make all-gcc && make install-gcc构建编译器(而不是其运行时库)。然后,您可以使用该GCC使用相同的$PATH_WHERE_YOU_WANT_THE_CROSS_COMPILER/bin构建newlib($PATH--target中)。然后,您可以构建另一个使用刚刚安装的newlib的GCC。

关于gcc - 使用现有的交叉编译器构建newlib,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49391116/

10-11 07:21