5
votes

I am trying to cross compile a simple hello world program for a linux system.

I have the following information:

uname -a
Linux (none) 2.6.32.28 #130 PREEMPT Mon Feb 18 13:54:18 CST 2013 armv5tejl GNU/Linux

cat /proc/cpuinfo
Processor       : ARM926EJ-S rev 5 (v5l)
BogoMIPS        : 421.06 
Features        : swp half fastmult edsp java
CPU implementer : 0x41
CPU architecture: 5TEJ
CPU variant     : 0x0
CPU part        : 0x926
CPU revision    : 5

Hardware        : KeyASIC Ka2000 EVM
Revision        : 0000
Serial          : 0000000000000000

I would like to know how to cross compile for this system. I have tried the following:

  • arm-linux-gnueabi-gcc helloworld.c -march=armv5 -o helloworld
  • arm-linux-gnueabi-gcc helloworld.c -mcpu=arm926ej-s -o helloworld

But when I try and run the executable I get the error message "command not found". I am probably not compiling it correctly but I don't know what compile options to use given the information I have.

(I know the helloworld.c is all working).

ls -l helloworld
-rwxr-xr-x    1 0        0             8428 Jan  1 00:00 helloworld

which helloworld
which: applet not found

I put busybox-armv5l on

busybox which helloworld
(no output)

ldd is also not on the system I am trying to compile for (its the transcend WifiSD card).

ls -ln /lib/libc*
-rwxrwxrwx    1 0        0           244279 Jan 19  2012 /lib/libc.so.0
-rwxrwxrwx    1 0        0            13043 Jan 19  2012 /lib/libcrypt.so.0
-rwxr-xr-x    1 0        0          1251776 Jan  1 00:00 /lib/libcrypto.so.0.9.8

I tried to run /lib/libc.so.0 to get version information and I got a segmentation fault. It seems compiling with -static fixed the issue. So I guess it was an issue with the libc library. Thank you for the help.

1
What's the output of the following commands inside the target system inside the directory where you copied helloworld? ls -l helloworld; which helloworld; ldd helloworld;Balau
Balau, I have updated the question with the outputs. (Couldn't add them to this comment.)Nick Horne
I hope you're trying to run it with './helloworld' and if so, try to compile it with '-static' flag. Warning though, binary will be significantly bigger.auselen
Please print the output of ls -l /lib/libc*.so /lib/libc.*. This shows the libc of the target. Your gcc version is glibc/eglibc. As well, the kernel may use OABI. You can use some options with ld to turn on debug, like ldd. export LD_DEBUG=all before attempting to run for example.artless noise
Thank you for the help, compiling with the static flag fixed the issue. I added results in the above post, it seems there is something wrong with libc. I would accept as an answer but it doesn't seem to have the option on a comment. I didn't try using export LD_DEBUG=all but ldd doesn't exist within PATH directories.Nick Horne

1 Answers

3
votes

I had to use -static flag to include c libraries in the binary. Thanks to auselen.