Trying to run a cross-compiled executable on target device fails with: No such file or directory

后端 未结 3 653
小蘑菇
小蘑菇 2021-02-05 16:04

I\'ve got caught in the not-so-sunny world of cross-compilation.

I\'m trying to compile a simple hello world application for my BeagleBone Black (which runs a TI Cortex-

3条回答
  •  独厮守ぢ
    2021-02-05 16:59

    Since nobody from the comments posted the answer, I guess I get the pleasure ;)

    No such file or directory comes from when the kernel tries to invoke the dynamic linker specified by the ELF executable's .interp field, but no such file exists.

    The .interp field can be found with the following command:

    objdump -j .interp -s ./hello_world
    

    In the case of this example, the executable's .interp field was /lib/ld-linux.so.3, but the name of the dynamic linker on the BeagleBone Black is /lib/ld-linux-armhf.so.3.

    This happened because the program was compiled with a slightly different toolchain to the one required for the platform. It should be arm-linux-gnueabihf-* rather than arm-linux-gnueabi-*.

    The difference between the two is that the Cortex-A8 uses specific floating point registers with the hard-float version (armhf) of the EABI, but the original EABI (armel) uses integer registers for passing around floating point numbers. As a result, armel programs will run on armhf (provided the dynamic linker is set to the correct path!), but not vice versa.

    Simply adding a symbolic link ln -s /lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3 is enough to resolve this issue, but the correct fix is to use the right toolchain when compiling the program in the first place.

提交回复
热议问题