Cross compilation for ARM based Linux embedded system

I am trying to compile C code for an ARM-based embedded (custom) system. I created a Ubuntu VM with a cross-compiler named arm-linux-gnueabi-gcc-4.4 because it looked the way I needed. Now, when I compile my code with this gcc, it generates a binary as follows:

$ file test1 test1: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=0x51b8d560584735be87adbfb60008d33b11fe5f07, not stripped 

When I try to run this binary in embedded Linux, I get

 $ ./test1 -sh: ./test1: not found 

Permissions are sufficient. I can only imagine that something is wrong with the binary format, so I looked at some working binary link:

 $ file referenceBinary referenceBinary: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), stripped 

I see that there are some differences, but I have no knowledge of what exactly I need to fix, and how I can fix it. Can someone explain what the difference is crucial?

Another thing I looked at is dependencies:

 $ ldd test1 libc.so.6 => not found (0x00000000) /lib/ld-linux.so.3 => /lib/ld-linux.so.3 (0x00000000) 

(Interestingly, this works on the target system, although it cannot execute the binary.) The embedded system only has libc.so.0 . I think I need to tell the compiler the version of libc that I want to link to, but as far as I understand, gcc just refers to the version with which it is linked, is that correct? What can i do with this?

Edit: Makefile is used here:

 CC=/usr/bin/arm-linux-gnueabi-gcc-4.4 STRIP=/usr/bin/arm-linux-gnueabi-strip CFLAGS=-I/usr/arm-linux-gnueabi/include LDFLAGS=-nostdlib LDLIBS=../libc.so.0 SRCS=test1.c OBJS=$(subst .c,.o,$(SRCS)) all: test1 test1: $(OBJS) $(CC) $(LDFLAGS) -o main $(OBJS) $(LDLIBS) $(STRIP) main depend: .depend .depend: $(SRCS) rm -f ./.depend $(CC) $(CFLAGS) -MM $^>>./.depend; clean: rm -f $(OBJS) include .depend 
+7
source share
1 answer

You should probably install libc6 on the embedded system. Read this thread about a similar issue. The solution in post # 5 was to set:

 libc6_2.3.6.ds1-13etch9_arm.deb linux-kernel-headers_2.6.18-7_arm.deb libc6-dev_2.3.6.ds1-13etch9_arm.deb 

Another option is to get libc from the embedded system to your virtual machine and pass it to the gcc linker and use the -static option.

This solution was also mentioned in the topic above. Read more about static binding here .

Other things to try:

To this thread, they suggest removing the -mabi=apcs-gnu flag from your makefile if you use it.

This article offers the gcc feed flag -nostdlib if you are compiling from the command line.

Or you can switch to using the arm-none-eabi-gcc compiler. Links to this can be found here here and here .

+4
source

All Articles