Cross-compile weirdness on Beagle running Debian

Hey folks,

I'm having a weird cross-compiling issue. Here's the simple program
(hello.c):

#include <stdio.h>

int main()
{
    fprintf(stdout,"Hello World\n");
    return 0;
}

I'm running Mint Debian on my dev system, and have been successfully
cross-compiling kernels for the past 3 days. Here is the command I
used to cross-compile hello.c:

arm-linux-gnueabi-gcc hello.c -o hello

It produces the hello binary, and the "file hello" produces:

hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically
linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

Running the hello binary on the Beagle Xm Rev C produces the following
output:

-bash: ./hello: No such file or directory

It's not a permissions issue:
-rwxr-xr-x 1 tony tony 5303 Feb 13 16:44 hello

Thanks in advance for any help.

-Tony

What does the command 'ldd hello' show? Also, what's in your
environment (i.e. run the command 'env')?

Hi,

It seems to me that you may be missing a shared library needed to run your recently compiled binary.
Try to compile with -static and check if the binary executes on the target.

If that works, then I’m pretty sure that you’re missing some library on your target system.

Good luck!

Try to compile with -static and check if the binary executes on the target.

Tone, that worked on the Beagle; hello produces the expected output.

What does the command 'ldd hello' show?

Ok, having recompiled it (without the -static option), ldd produces:

not a dynamic executable

run the command 'env'?

Output:

ORBIT_SOCKETDIR=/tmp/orbit-tony
SSH_AGENT_PID=2124
GPG_AGENT_INFO=/tmp/keyring-wqVsDS/gpg:0:1
TERM=xterm
SHELL=/bin/bash
XDG_SESSION_COOKIE=d012284f9cacbc963a4b500900000a23-1329149796.678679-339279491
GTK_RC_FILES=/etc/gtk/gtkrc:/home/tony/.gtkrc-1.2-gnome2
WINDOWID=16777222
OLDPWD=/home/tony
GNOME_KEYRING_CONTROL=/tmp/keyring-wqVsDS
SIMLOCDIR=/home/tony/seaotter/src/trunk/bin/locations
GTK_MODULES=canberra-gtk-module
SVN_EDITOR=vim
USER=tony
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
SSH_AUTH_SOCK=/tmp/keyring-wqVsDS/ssh
SESSION_MANAGER=local/abadlaptop:@/tmp/.ICE-unix/2092,unix/abadlaptop:/tmp/.ICE-unix/2092
USERNAME=tony
PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/sbin
DESKTOP_SESSION=default
SIMICONDIR=/home/tony/seaotter/src/trunk/bin/icons
PWD=/home/tony/Desktop
GDM_KEYBOARD_LAYOUT=us
GNOME_KEYRING_PID=2072
LANG=en_US.UTF-8
GDM_LANG=en_US.UTF-8
GDMSESSION=default
SHLVL=1
HOME=/home/tony
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
SIMDIR=/home/tony/seaotter/src/trunk
LOGNAME=tony
XDG_DATA_DIRS=/usr/share/gnome:/usr/share/gdm/:/usr/local/share/:/usr/share/
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-RbeDOK6z1g,guid=2bb94317e34d212b9ffbdc0700000027
WINDOWPATH=7
DISPLAY=:0
COLORTERM=gnome-terminal
XAUTHORITY=/var/run/gdm3/auth-for-tony-XTjQPm/database
_=/usr/bin/env

Thanks,

Tony

Try to compile with -static and check if the binary executes on the target.

Tone, that worked on the Beagle; hello produces the expected output.

What does the command 'ldd hello' show?

Ok, having recompiled it (without the -static option), ldd produces:

not a dynamic executable

You should run this on a version not compiled with -static so we can see
what dynamic libraries are missing, thus making it not executable.

  run the command 'env'?

Output:

ORBIT_SOCKETDIR=/tmp/orbit-tony
SSH_AGENT_PID=2124
GPG_AGENT_INFO=/tmp/keyring-wqVsDS/gpg:0:1
TERM=xterm
SHELL=/bin/bash
XDG_SESSION_COOKIE=d012284f9cacbc963a4b500900000a23-1329149796.678679-339279491
GTK_RC_FILES=/etc/gtk/gtkrc:/home/tony/.gtkrc-1.2-gnome2
WINDOWID=16777222
OLDPWD=/home/tony
GNOME_KEYRING_CONTROL=/tmp/keyring-wqVsDS
SIMLOCDIR=/home/tony/seaotter/src/trunk/bin/locations
GTK_MODULES=canberra-gtk-module
SVN_EDITOR=vim
USER=tony
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.

xwd=01;35
:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:

You should run this on a version not compiled with -static so we can see
what dynamic libraries are missing, thus making it not executable.

I did. That's the output without the -static option.

Thanks,

Tony

Tony,

When something similar hapens to me it usually turns out to be some some symlink missing in /lib or /usr/lib.

Check the library dependencies of the dinamically linked binary. Then check if all the dependencies are present in your target.

Cheers,

Check the library dependencies of the dinamically linked binary. Then check
if all the dependencies are present in your target.

That makes sense. But the problem is that:

arm-linux-gnueabi-gcc hello.c -o hello

produces a file such that ldd hello

not a dynamic executable

Even if I explicitly link to a library, say pthreads (e.g.
arm-linux-gnueabi-gcc hello.c -o hello -lpthread), ldd produces the
same output: not a dynamic executable.

I'm beginning to suspect that something is screwy with my toolchain.
But if that's the case, then how I was able to compile kernels for the
past 3 days on the same machine, using the same toolchain?

Thanks,

Tony

The Linux kernel is not built the same as user code - same compiler, but
the results are quite different, so it's easy to understand that compiling
the kernel might go OK, but user programs not so much so.

Your first email in this thread _did_ have a shared binary, i.e. not static.
Somehow you created it once :slight_smile: Try creating it to a new file, e.g.
   # arm-linux-gnueabi-gcc hello.c -o hello.shared

Then when you run
   # ldd hello.shared
you should see something like this:
   # ldd /bin/sh
         libc.so.6 => /lib/libc.so.6 (0x400ff000)
         /lib/ld-linux.so.3 (0x400bf000)

Then it's just a matter of tracking down the missing libraries.

Check the library dependencies of the dinamically linked binary. Then check
if all the dependencies are present in your target.

That makes sense. But the problem is that:

arm-linux-gnueabi-gcc hello.c -o hello

produces a file such that ldd hello

not a dynamic executable

Even if I explicitly link to a library, say pthreads (e.g.
arm-linux-gnueabi-gcc hello.c -o hello -lpthread), ldd produces the
same output: not a dynamic executable.

Did you use host ldd or

I’m beginning to suspect that something is screwy with my toolchain.
But if that’s the case, then how I was able to compile kernels for the
past 3 days on the same machine, using the same toolchain?

The fact that the toolchain compiles a kernel and the system boots, alone, doesn’t mean the cross-toolchain is working… There may be indeeded something wrong with the tool but it may also be working just fine.
Was the target built using the same toolchain that you used to build the binary?
Are the shared libraries of your target the same that are present in the cross toolchain?
You can also find the library dependencies of your binary using objdump of the cross-toolchain. I don’t have a linux box handy to check the correct parameters but it shouldn’t be hard to find out.

Cheers,
Tone

The Linux kernel is not built the same as user code - same compiler, but
the results are quite different, so it's easy to understand that compiling
the kernel might go OK, but user programs not so much so.

Thank you for that explanation. It relieves some of the worry I had
that maybe my kernel compile was a ticking time bomb waiting to blow
up.

Your first email in this thread _did_ have a shared binary, i.e. not static.
Somehow you created it once :slight_smile: Try creating it to a new file, e.g.
# arm-linux-gnueabi-gcc hello.c -o hello.shared

No, the result has always been the same when running ldd hello: "not a
dynamic executable." The first output I printed was from running file
hello.

I think I may have figured out the issue. On the Beagle, I'm running
a 12.04 armhf image. But I don't think the arm-linux-gnueabi-gcc
toolchain works on armhf kernels. To confirm this, I flashed an 11.10
image, booted it up on the Beagle, and transferred over the
cross-compiled program. It worked correctly. Furthermore, ldd
outputs what we all expect:
  libc.so.6 => /lib/arm-linux-gnueabi/libc.so.6 (0x40125000)
  /lib/ld-linux.so.3 (0x40028000)

In addition to Tone and Gary's help, what tipped me off was running
ldd on the hello binary when it was compiled natively on the Beagle
12.04 armhf image:
  libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x401f9000)
  /lib/arm-linux-gnueabihf/ld-linux.so.3 (0x40051000)

So now I have to figure out how to get the appropriate toolchain
installed on my laptop (running Linux Mint...for which updates are,
well, sparse).

Thanks for your help,

-Tony

Why can't you just build your application natively on the beagle?

Regards,

Why can't you just build your application natively on the beagle?

I can. In fact, that's what I've been doing on the Beagle for the
past 4 months or so. I just figured maybe it was time to start
cross-compiling, especially after now having done it from the kernel
source. Just something new to learn.

Regards,

Tony