I have some compilers for different architectures:
$ > whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/share/man/man1/gcc.1.gz
$ > whereis arm-linux-gnueabi-gcc
arm-linux-gnueabi-gcc: /usr/bin/arm-linux-gnueabi-gcc /usr/share/man/man1/arm-linux-gnueabi-gcc.1.gz
$ > whereis arm-linux-gnueabihf-gcc
arm-linux-gnueabihf-gcc: ~/.local/bin/arm-linux-gnueabihf-gcc
gcc is for my workstation. It was installed in system path.
arm-linux-gnueabi-gcc is for ARM target without hard float. It was installed in system path too.
arm-linux-gnueabihf-gcc is for ARM target with hard float. It was installed in my $(HOME)/.local/
directory.
And I have added this directory to binary path in the .bashrc
script:
export PATH="$HOME/.local/bin:$PATH"
The system command whereis
works true for all this compilers and shows valid path to binary executable file.
I wanted to compile some project for ARM with help arm-linux-gnueabihf-gcc
compiler, but I have received this:
as: unrecognised option '-mcpu=cortex-a53'
Error during assembler. Seems that my build system wish to use assembler for my x86, not arm-linux-gnueabihf-as
.
After the installing arm-linux-gnueabihf
to ~/.local
into the one some directories are appeared:
~/.local> ls -l
arm-linux-gnueabihf/
bin/
gcc-linaro-5.3.1-2016.05-linux-manifest.txt
include/
lib/
libexec/
share/
If i will go to bin/
I will see the binbary files:
arm-linux-gnueabihf-addr2line* arm-linux-gnueabihf-cpp* arm-linux-gnueabihf-gcc-ar* arm-linux-gnueabihf-gdb* arm-linux-gnueabihf-nm* arm-linux-gnueabihf-size* isort*
arm-linux-gnueabihf-ar* arm-linux-gnueabihf-elfedit* arm-linux-gnueabihf-gcc-nm* arm-linux-gnueabihf-gfortran* arm-linux-gnueabihf-objcopy* arm-linux-gnueabihf-strings* pylint*
arm-linux-gnueabihf-as* arm-linux-gnueabihf-g++* arm-linux-gnueabihf-gcc-ranlib* arm-linux-gnueabihf-gprof* arm-linux-gnueabihf-objdump* arm-linux-gnueabihf-strip* pyreverse*
arm-linux-gnueabihf-c++* arm-linux-gnueabihf-gcc* arm-linux-gnueabihf-gcov* arm-linux-gnueabihf-ld* arm-linux-gnueabihf-ranlib* epylint* runtest*
arm-linux-gnueabihf-c++filt* arm-linux-gnueabihf-gcc-5.3.1* arm-linux-gnueabihf-gcov-tool* arm-linux-gnueabihf-ld.bfd* arm-linux-gnueabihf-readelf* gdbserver* symilar*
This path was added to $PATH
.
But if i will go to ./arm-linux-gnueabihf/bin
and will do ls
, i will receive empty directory.
I can overcome the error, if i will add some symbolic links to this directory:
ar -> ../../bin/arm-linux-gnueabihf-ar*
as -> ../../bin/arm-linux-gnueabihf-as*
gcc -> ../../bin/arm-linux-gnueabihf-gcc*
ranlib -> ../../bin/arm-linux-gnueabihf-ranlib*
strip -> ../../bin/arm-linux-gnueabihf-strip*
...
After this my assembler error disappears and I can successfully compile project for ARM-target. But after this I can't compile anything for my workstation x86.
Could anyone explain me what i should to do to successful compiling and for ARM and for x86, please?
UPD: I have the Makefile for ARM:
CROSS_COMPILE = arm-linux-gnueabihf-
CC = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)as
INCLUDES = -I./
SRC = main.c
TARGET = my-arm-target
all: $(SRC)
$(CC) $(INCLUDES) -o $(TARGET)
And the same file for x86, but without CROSS_COMPILE
variable:
CC = gcc
AS = as
INCLUDES = -I./
SRC = main.c
TARGET = my-x86-target
all: $(SRC)
$(CC) $(INCLUDES) -o $(TARGET)
You can set up a script for each architecture you want and use it to switch environments so you are using that architecture's tools. makefiles for a specific architecture may assume gcc is the appropriate compiler, so your script should ensure that. example:
source the above script (. script) before your run your makefile, then the appropriate tools should be used. Note, some of the items are commented out in the above example since I didn't need them.