'How can I execute a C program on Qemu riscv and observe the output?

What should be the best approach to run a C code in Qemu riscv and observe the output? I installed Qemu riscv following this link.What should I do now?

https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html



Solution 1:[1]

You probably want to use the static user mode version of Qemu for most applications. Then make sure to compile for RISC-V with the -static flag, and call qemu-riscv64-static [executable]. I highly recommend this, the system mode is a massive pain to handle if you don't need it (have fun debugging the UART).

Solution 2:[2]

You can use libriscv to run RISC-V programs: https://github.com/fwsGonzo/libriscv

Inside the emulator folder there are 2 ways to build the emulator. build.sh produces emulators that run programs with no instruction listing. debug.sh produces debugging variant that shows the state of registers and instructions all the way through the program.

Building Qemu from sources is complete overkill.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 schorrm
Solution 2 gonzo