I can't seem to build Rust as a cross-compiler, either on Windows with MSYS2 or on a fresh install of Debian Wheezy. The error is the same for both. I run this configure:
./configure --target=arm-unknown-linux-gnueabihf,x86_64-pc-windows-gnu
make works, but then make install fails with:
[...]
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/rustdoc-*.dll
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/fmt_macros-*.dll
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/libmorestack.a
prepare: tmp/dist/rustc-1.0.0-dev-x86_64-pc-windows-gnu-image/bin/rustlib/x86_64-pc-windows-gnu/lib/libcompiler-rt.a
compile: arm-unknown-linux-gnueabihf/rt/arch/arm/morestack.o
make[1]: arm-linux-gnueabihf-gcc: Command not found
/home/Sandro/rust/mk/rt.mk:94: recipe for target 'arm-unknown-linux-gnueabihf/rt/arch/arm/morestack.o' failed
make[1]: *** [arm-unknown-linux-gnueabihf/rt/arch/arm/morestack.o] Error 127
make[1]: Leaving directory '/home/Sandro/rust'
/home/Sandro/rust/mk/install.mk:22: recipe for target 'install' failed
make: *** [install] Error 2
Everything builds fine if I don't specify a cross architecture. Am I missing some special configure flag to make this work?
The error message says that make did not find the arm-linux-gnueabihf-gcc binary, which is supposed to be a C compiler producing ARM code. That means that you probably don't have any ARM C cross-compilation toolchain installed.
I know Ubuntu has packages for cross compilers (gcc-arm-linux-gnueabihf in 14.04) so Debian may have the same packages. You can also find fully packaged ARM C cross-compilers for Windows and Linux on the Linaro website. If you are building for the Rapsberry Pi, you can also find toolchains to build for Raspbian and Archlinux on https://github.com/raspberrypi/tools.
Here is an example under Linux with a Linaro toolchain (should be distribution-agnostic for the host)
$ wget http://releases.linaro.org/14.11/components/toolchain/binaries/arm-linux-gnueabihf/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz
$ tar -xf gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz
$ export PATH=$PATH:$PWD/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin
$ cd <your_configured_rustc_build_directory>
$ make
You can then use the cross compiler with the following line. You can provide the full path to the arm-linux-gnueabihf-gcc binary if you don't want to put it in your PATH.
rustc --target=arm-unknown-linux-gnueabihf -C linker=arm-linux-gnueabihf-gcc hello.rs
If you are using Cargo, you can specify the linker to use for each target in the .cargo/config with this option:
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
Related
I am trying to cross-compile the Linux kernel for the beaglebone black on Ubuntu 22.04 using the command line below:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- bb.org_defconfig
I get the following error:
HOSTCC scripts/basic/fixdep
/bin/sh: 1: gcc: not found
make[2]: *** [scripts/Makefile.host:90: scripts/basic/fixdep] Error 127
make[1]: *** [Makefile:467: scripts_basic] Error 2
make: *** [Makefile:633: include/config/auto.conf.cmd] Error 2
As a result of various searches, I have verified that I have arm-linux-gnueabi-gcc in /bin:
/bin$ find . -maxdepth 1 -name "*gcc*" -print
./arm-linux-gnueabi-gcc-ranlib-11
./arm-linux-gnueabihf-gcc
./arm-linux-gnueabi-gcc-11
./arm-linux-gnueabi-gcc-nm
./arm-linux-gnueabihf-gcc-nm
./arm-linux-gnueabi-gcc-ranlib
./arm-linux-gnueabi-gcc-nm-11
./arm-linux-gnueabihf-gcc-ranlib
./arm-linux-gnueabihf-gcc-ar-11
./arm-linux-gnueabihf-gcc-ranlib-11
./arm-linux-gnueabihf-gcc-11
./arm-linux-gnueabi-gcc-ar
./arm-linux-gnueabihf-gcc-nm-11
./arm-linux-gnueabi-gcc
./arm-linux-gnueabihf-gcc-ar
./arm-linux-gnueabi-gcc-ar-11
that my path includes /bin:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
What am I missing?
In short: When cross-compiling Linux kernel, you need not only a cross-compiler, but a compiler (gcc) for your host too.
When build the Linux kernel and modules, the build system not only compiles binaries for the target platform, but also executes some programs on these binaries. These programs are shipped with the Linux kernel sources as sources, so for build these programs host compiler is needed.
By the way, a line started with HOSTCC means that exactly host compiler is used for that operation.
I tried to compile the Linux kernel 3.10.31 on Ubuntu 16.04 LTS.
I used to compile the exact same kernel on Ubuntu 12.04 LTS, and everything works well.
On Ubuntu 16.04, the gcc version is gcc-5;
On Ubuntu 12.04, the gcc version is gcc-4.6.
It seems that the Linux kernel kernel before 3.18 cannot compile with the gcc-5. The kernel 3.10.31 reports the following error when it is compiled by make
fatal error: linux/compiler-gcc5.h: No such file or directory
I tried to install gcc-4.7 onto Ubuntu 16.04 and change the /usr/bin/gcc to point to the gcc-4.7. This could solve the above error. However, it leads to new issues after I run make
$linux/arch/x86/Makefile:98: stack protector enabled but no compiler support
make[1]: Nothing to be done for 'all'.
make[1]: Nothing to be done for 'relocs'.
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CC kernel/bounds.s
gcc-4.7.real: error: unrecognized command line option ‘-no-pie’
linux/./Kbuild:35: recipe for target 'kernel/bounds.s' failed
make[1]: *** [kernel/bounds.s] Error 1
Makefile:835: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2
My question is:
Is there a neat way to use the old compiling chain to compile the old kernel 3.10.31 on Ubuntu 16.04?
Thank you very much for your help! Any advice is really appreciated.
I think I figured out a solution.
We don't have to install the old version gcc. We only need to copy the file compiler-gcc5.h from here or from here into include/linux/. It will solve the compilation issue.
Ubuntu 16.04 now still supports gcc-4.7 so you can install it and then you can choose the version of gcc before using it by update-alternatives.
For examples:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --config gcc # here you choose by hint
If you directly download compiler-gcc5.h, you may meet problems like arch/x86/kvm/svm.c error invalid character that I met when compiling 3.3.8 in Ubuntu 16.04.3 x64.
Open the Makefile, look for CFLAGS_EXTRA and add the following option to it -fno-pie.
See, https://askubuntu.com/questions/851433/kernel-doesnt-support-pic-mode-for-compiling.
I am trying to compile a gcc from source since I cannot use yum, apt-get and so forth. My steps are simple:
-I download the source GCC (I tried gcc-4.8.4 and gcc-5.3.0) in my pc and I used:
./contrib/download_prerequisites
-After this, I send this my gcc source file to my system using powerPC y Linux.
mkdir objdir
cd objdir
../gcc-4.6.2/configure --prefix=/usr --enable-languages=c,c++,fortran,go
make
I have got the next error:
In file included from ../../gcc-4.9.2/gcc/genmddeps.c:19:0:
../../gcc-4.9.2/gcc/system.h:205:20: fatal error: cstring: No such file or directory
# include <cstring>
^
compilation terminated.
make[3]: *** [build/genmddeps.o] Error 1
make[3]: Leaving directory `/home/root/build/gcc'
make[2]: *** [all-stage1-gcc] Error 2
make[2]: Leaving directory `/home/root/build'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/root/build'
make: *** [all] Error 2
Any idea about what it is going wrong?
Best regards
Some advice: first, compile (notably for learning purposes) something simpler than GCC, e.g. GNU make if you never compiled GNU stuff from source code.
Then compile a recent GCC (so 5.3 in january 2016) - building issues would be the same with 4.8, and GCC 5 is better! You need the gcc & libc-dev & g++ & libstdc++-dev for your host machine (the one running your future cross-compiler). I am not sure your --prefix=/usr is a good idea. Consider perhaps a --program-suffix=-mine option (otherwise, your system's /usr/bin/gcc could be overwritten, which you don't want to happen)
You could leave the default --prefix=/usr/local and later add appropriately /usr/local/bin/ into your PATH
I have a new installation of Ubuntu linux and I am trying to update my gcc complier. The latest gcc compiler depends on gmp, mpfr, and mpc, so I downloaded those and placed the source into the gcc 4.8.1 source folder, as instructed.
configure seems to have run just fine. I did not include any options, because none seemed appropriate. I just ran with the defaults.
When I run make, I get the following error:
configure: error: C++ compiler missing or inoperational
make[2]: \*** [configure-stage1-libcpp] Error 1
make[2]: Leaving directory `/home/clay/programming/C++/gcc-4.8.1'
make[1]: \*** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/clay/programming/C++/gcc-4.8.1'
make: \*** [all] Error 2
I am running out of a terminal window as root, and I did a make distclean and tried a second time, but no dice. I know it can find both gcc and cc because it says so in the make output.
Any ideas?
You need a C++ compiler to build GCC. On Ubuntu, the C++ compiler is in the package g++, separate from gcc (which is a C compiler, not a C++ compiler), so be sure to:
sudo apt-get install g++
first you should ensure a C++ compiler to build on your machine
yum install gcc-c++
I try to cross-compiler icu4c 51.1 with Emscripten (clang) via
emconfigure source/configure --host=i386-pc-linux-gnu --prefix=${myprefix} --enable-static --disable-shared --disable-dyload --disable-renaming CXXFLAGS='-DU_USING_ICU_NAMESPACE=0' CPPFLAGS='-DU_DISABLE_RENAMING=1'
emmake make
emmake make install
It compiles most of the sources fine, but fails with
Unpacking ../source/data/in/icudt51l.dat and generating out/tmp/icudata.lst (list of data files)
LD_LIBRARY_PATH=../lib:../stubdata:../tools/ctestfw:$LD_LIBRARY_PATH ../bin/icupkg -d ./out/build/icudt51l --list -x \* ../source/data/in/icudt51l.dat -o out/tmp/icudata.lst
run-detectors: warning: unable to exec /usr/bin/lli-2.8: No such file or directory
run-detectors: warning: unable to exec /usr/bin/lli-2.9: No such file or directory
LLVM ERROR: Program used external function 'findBasename' which could not be resolved!
make[1]: *** [out/tmp/icudata.lst] Error 1
make[1]: Leaving directory `/home/andreas/.emscripten-libs/sources/icu4c/51.1/data'
make: *** [all-recursive] Error 2
So I am wondering, where it tries to find findBasename and what this data compiling is all about.
EDIT:
The error messages come from icupkg being built with clang, which does not make sense in this case. How can I specifc that the libraries are built with clang, but the tools with another compiler?
Sounds like it wasn't able to find, I'm guessing, ICU tool utilities lib in ../lib - might try running ldd or equivalent on icupkg