linux-kernelbeagleboneblackbuildrootbeagleboardrootfs

Why can't I run custom application on my Beaglebone board?


I have cross-compiled the small application for my beaglebone board:

/* led_test.c */

int main(int argc, char const *argv[])
{
    return 0;
}

Compiling was done successfully, but if I try to run the application in target board, I get this:

# cd /bin/
# ls -la | grep led_test
-rwxr-xr-x    1 default  default      13512 Feb  5  2020 led_test
# led_test 
-sh: ./led_test: not found

Why can't I run custom application on my Beaglebone board? Could anyone explain me it, please?

Some information about my environment:

1. work-station: Ubuntu 18.04.4 LTS x86-64
2. target machine: ARMv7 beaglebone board
3. cross-compiler: gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf
4. I built u-boot and Linux kernel with this toolchain and mounted rootfs via NFS.

UPD 1:

I tried use this ./led_test instead led_test. It doesn't matter, because my application is placed into /bin directory.


Solution

  • It's likely your userspace was not built with the cross-toolchain that you compiled your binary with. Maybe you compiled the kernel with it, but that does not matter, what matters is the rootfs.

    Your program is dynamically linked. When the program runs, the kernel really loads the dynamic linker, and that then maps the executable into the process's address space along with the libraries.

    To see the dynamic linker, run readelf -l on your host or target system on the binary. Example:

    $ readelf -l a.out
    
    Elf file type is EXEC (Executable file)
    [... more lines ...]
          [Requesting program interpreter: /lib/ld-linux-armhf.so.3]
    [... more output ...]
    

    The line with program interpreter is the one to look file. file will also give this information. It's probably the case the the file named here is not preset on your rootfs. That is the "file not found" that the error is from.

    What you need to do is use the correct cross-toolchain (which uses the same C library version) for the rootfs you are using or build a new rootfs with the same toolchain.

    Take a look at buildroot for an easy way to make a new, simple, BeagleBone Black rootfs that's way faster and simpler than using Yocto/Poky to make one.