skip to Main Content

I am trying to cross compile a small rust application for the RPI. I am cross compiling because compiling directly on the PI takes way too long and it hits 75C.

I followed various instructions, but what I ended up doing is this:

  • Install "armv7-unknown-linux-gnueabihf" target with rustup
  • Download rpi tools from here: https://github.com/raspberrypi/tools
  • Add the "tools/arm-bcm2708/arm-linux-gnueabihf/bin/" folder to PATH
  • Add ".cargo/config" file with:
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
  • run "cargo build –target armv7-unknown-linux-gnueabihf –release"
  • scp the file to the RPI
  • chmod +x the_file
  • do "./the_file"

I get bash: ./the_file: No such file or directory

Yes, I am indeed in the right directory.

So this is the output from "file":

ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically
linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32,
with debug_info, not stripped

I’m not experienced enough with this sort of stuff to determine if the binary that I produced is suitable to be run on an RPI3 B.

Did I produce the correct "type" of binary?

P.S. I am running DietPi distro on the PI. It is based on debian if that’s of any relevance.

2

Answers


  1. Chosen as BEST ANSWER

    So I solved this by cheating. I found https://github.com/rust-embedded/cross which took about 30 seconds to get going and now I can cross compile to pretty much anything. I highly recommend it!


  2. The error message "No such file or directory" is not about the your executable but about the dynamic libraries linked to it which are missing from the target system.
    To find out which libraries your executable needs you have to run the following command.

    ldd /usr/bin/lsmem
    

    This will output something like this

    linux-vdso.so.1 (0x00007fffc87f1000)
    libsmartcols.so.1 => /lib/x86_64-linux-gnu/libsmartcols.so.1 (0x00007fe82fe71000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe82fc7f000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe82fedd000)
    

    Now you have to check that all this libraries are available on your system. rust-cross probably uses the correct linker for your target so that is probably the reason this works with it. To modify the linker see https://stackoverflow.com/a/57817848/5809980

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search