Crt1.o error in cross-compiler mips

I would like to create MIPS binaries using gcc on an x86 machine. To install the MIPS cross compiler, I followed the directions on this page . I could install gcc and binutils successfully. I tried to compile a simple hello world program using a cross compiler.

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -mips1 hi.c 

      

I got the following error.

/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crti.o: No such file or directory
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find -lc
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

      

I did some research on the internet to figure out what the problem is and changed the command I used for the following.

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -B/usr/lib/i386-linux-gnu -mips1 hi.c

      

Now I am getting this error message:

/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: /usr/lib/i386-linux-gnu/crt1.o: Relocations in generic ELF (EM: 3)
/usr/lib/i386-linux-gnu/crt1.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status

      

I'm not sure what the problem is. The only thing I can think of is the "no headers" option that is passed to configure the program when gcc is built. Configure the command for gcc given on the linux-mips page as follows.

% ../gcc-3.8.2/configure --target=$TARGET --prefix=$PREFIX \
  --enable-languages=c --without-headers \
  --with-gnu-ld --with-gnu-as \
  --disable-shared --disable-threads \
  --disable-libmudflap --disable-libgomp \
  --disable-libssp --disable-libquadmath \
  --disable-libatomic

      

I would appreciate some help. The system I generated the cross compiler on uses gcc4.7.2-5. I have used sources for gcc-4.8.2 and binutils-2.24 to generate a cross compiler.

+3


source to share


2 answers


/ opt / cross / bin / mipsel-unknown-linux-gnu-gcc -mips1 hi.c

Add the command SYSROOT

to the compile command. It should look like this:

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -mips1 --sysroot=/opt/cross/... hi.c

      

SYSROOT

will automatically provide the header and library path (instead of adding -I

and -L

separately).

You will know when you have SYSROOT

, because the path used will have bin/

, include/

and lib/

. For example, here SYSROOT

for arm-linux-gnueabi

(i.e. arm-linux-gnueabi-gcc

and arm-linux-gnueabi-g++

):



$ ls /usr/arm-linux-gnueabi
bin  include  lib

      

So in this example, you would use --sysroot=/usr/arm-linux-gnueabi

.

If you need help finding SYSROOT

, run the command find

:

$ find /usr -name crt1.o
/usr/arm-linux-gnueabi/lib/crt1.o
/usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o
/usr/lib/x86_64-linux-gnu/crt1.o

      

In your case, you will probably be looking from /opt/cross

. Obviously you want an object for target ( arm-linux-gnueabi

), not one for host ( x86_64-linux-gnu

).

+2


source


Adding --sysroot = will resolve this issue. Since you are cross-compiling, you should not only select any other folder that has crt1.o or crtX.o as your sysroot directory. These could be your host's files. (What if you are on x86 it will be for x86). Again it changes from 32 bit and 64 bit.



With a newer version of the GCC toolchain, you need to have a sdk portion that has a matching sysroot and crt1.o. This should come with your ABI and your target architecture.

0


source







All Articles