3

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 need to have a Makefile for that, use that file as a script for cross-compilation (you would need to add cross-compiler path inside, and all options needed also); with this method, you can use your x86 compiler without any change – damadam Oct 15 '19 at 13:41
  • @damadam I have updated my post with adding Makefiles. – Anisyanka Oct 15 '19 at 14:02
  • If I wll add the link gcc -> ../../bin/arm-linux-gnueabihf-gcc* and others I will compile only for ARM. And not for x86 – Anisyanka Oct 15 '19 at 14:04
  • after creating a Makefile, you have to use the make command to do the cross-compilation (there is probably more to do before and after, i didn't remember) - i will confirm that by watching my previous report this evening – damadam Oct 15 '19 at 14:12
  • Yes, I use make command to build this. ~ cd arm-proj; ~ make; **success**! And then: ~ cd ../x86-proj ~ make **as error**! – Anisyanka Oct 15 '19 at 14:19
1

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:

MY_ARM_BASE=${HOME}/dev/toolchain/arm-2008q3
C_INCLUDE_PATH=${MY_ARM_BASE}/lib/gcc/arm-none-linux-gnueabi/4.3.2/include:${MY_ARM_BASE}/lib/gcc/arm-none-linux-gnueabi/4.3.2/include-fixed
LIBRARY_PATH=${MY_ARM_BASE}/arm-none-linux-gnueabi/libc/lib:${MY_ARM_BASE}/arm-none-linux-gnueabi/libc/usr/lib
CPLUS_INCLUDE_PATH=${MY_ARM_BASE}/arm-none-linux-gnueabi/include/c++/4.3.2
#OBJC_INCLUDE_PATH
COMPILER_PATH=${MY_ARM_BASE}/bin
#LD_RUN_PATH
#GPROF_PATH
#######
CC=${COMPILER_PATH}/gcc
CXX=${COMPILER_PATH}/g++
RANLIB=${COMPILER_PATH}/ranlib
STRIP=${COMPILER_PATH}/strip
export C_INCLUDE_PATH LIBRARY_PATH CPLUS_INCLUDE_PATH COMPILER_PATH
export CC CXX RANLIB STRIP

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.

| improve this answer | |
  • No, unfortunately it doesn't work. If I will compile the Linux kernel for ARM I will get errors, because it needs simultaneously and gcc-x86(my workstation) and gcc-arm(my target). – Anisyanka Oct 24 '19 at 9:10
  • Please pay attention to the links which I remove for normal gcc-x86 work (see question). May be I have problems there. – Anisyanka Oct 24 '19 at 9:14
  • I removed links and reinstalled arm-compiler. It's true way :) – Anisyanka Oct 31 '19 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.