riscv-software-src / riscv-tools

RISC-V Tools (ISA Simulator and Tests)
1.13k stars 446 forks source link

issue with execution of c program #265

Open PriyankaR611 opened 5 years ago

PriyankaR611 commented 5 years ago

i am tring to execute hello world c program on riscv-linux i compiled code using the following command riscv64-unknown-linux-gnu-gcc -o test test.c and got its executable. i saved that executable in root folder of linux n tried to execute it in ash terminal using simulator by this command ./test but giving error as -/bin/ash: ./test: not found

please give me solution for this thank you

jim-wilson commented 5 years ago

This error means that the program interpreter is missing. Bash gives a much better error message than ash does. You can see the same error if you create a shell script like this

#!/bin/nonexistant
exit 0

and try to run it.

For a binary, the program interpreter is the dynamic linker. If you go back to your host system, and run "riscv64-unknown-linux-objdump --full-contents --section .interp test" it will print the name of the dynamic linker. This file is missing on your target system. This problem usually occurs when your cross compiler and your target system are using different glibc versions. The glibc versions must match if you want dynamic libraries to work. Or maybe the glibc on your target was built without shared library support.

The simple workaround is to static link binaries. Add the --static option to the gcc command to get a statically linked binary, which then should run on your target.