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
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.
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?
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 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.
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 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).
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.