Cross compiling for Raspberry pi 2 error

1.7k views Asked by At

I wanted to start cross compiling for raspberry pi2 on Ubuntu 32bit (in virtual box), so I downloaded the toolchain on the github site (https://github.com/raspberrypi/tools) and tried to compile a simple hello world program with the command (I've included the path to the bin folder that contains arm-linux-gnueabihf-gcc-4.8.3 to the PATH variable.):

arm-linux-gnueabihf-gcc-4.8.3 HelloWorld.c

However, I always get the following error message:

path/to/the/linker/in/the/toolchain/ld:/path/to/the/libc.so.6file/in/the/toolchain/libc.so.6: file format not recognized; treating as linker script

and subsequently a syntax error. When I look into libc.so.6, I see a single line containing:

libc-2.13.so

The libc-2.13.so file is present in the same folder as the libc.so.6 file. When I invoke

file libc-2.13.so

I get:

libc-2.13.so: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), BuildID[sha1]=dbd0cdca5a677bea1417be1272f4c5ef43bd3e22, for GNU/Linux 2.6.26, stripped

I don't know what could cause this error since obviously the linker from the toolchain and the libc.so.6 file from the toolchain are processed so the file format should be recognized, right? Can someone point me in the right direction here? Thanks!

3

There are 3 answers

6
Amol Saindane On BEST ANSWER

I will suggest you alternate way to do Cross compilation. I tried it and it works. You can use crosstool-NG. It gives you graphical way to setup your toolchain for cross compilation. There are lot of option for setting up toolchain. You can explore that.

Now you are doing for ARM-RPi but tomorrow if your Target CPU changed then it will be very easy to reconfigure the toolchain again.

You can find easy steps given in this article. I hope this works for you.

1
Roy Longbottom On

In my first effort, I had to include the path to gcc in the command. Then I just compiled programs on the RPi.

  ~/toolchain/raspbian-toolchain-gcc-4.7.2-linux32/bin/arm-linux-gnueabihf-gcc whets.c 
0
skidaddytn On

When I look into libc.so.6, I see a single line containing: libc-2.13.so

I just ran into this. The problem is way simpler than you think. When you un-gz'd and untar'd the toolchain, what happened is that libc.so.6 became a text file. It is supposed to be a "symbolic link" file pointing at the correct file "libc-2.13.so".

If you are using windows and 7-Zip, make sure to click "Run AS Administrator" when you start 7-zip. If you simply drag and drop, the error is not so obvious.