Error: elf32lriscv: No such file or directory

Hi, I’m having a bit of an issue with ABI target emulation. When I try to build my project, I ended up getting this error message below.

riscv64-unknown-elf-gcc: error: elf32lriscv: No such file or directory
riscv64-unknown-elf-gcc: error: elf32-littleriscv: No such file or directory
riscv64-unknown-elf-gcc: error: unrecognized command line option ‘-m’
riscv64-unknown-elf-gcc: error: unrecognized command line option ‘-EL’; did you mean ‘-E’?
riscv64-unknown-elf-gcc: error: unrecognized command line option ‘-b’
riscv64-unknown-elf-gcc: error: unrecognized command line option ‘–check-sections’; did you mean ‘–data-sections’?
riscv64-unknown-elf-gcc: error: unrecognized command line option ‘–wrap=printf’; did you mean ‘–cray-pointer’?
make: *** [makefile:44: demo.elf] Error 1

the code in “Other linker flags” part of wsFreedomStudio:

-t -nostdinc --entry _start -m elf32lriscv -EL -b elf32-littleriscv --check-sections --wrap=printf -t

Please let me know if you need to know anything else.
Thank you so much for your help in advance.

Those are linker options. You either need to call the linker (ld) directly instead of using gcc, or you need to escape the linker options that gcc doesn’t directly handle. You can use for instance "-Wl,-m,elf32lriscv: instead of “-m elf32lriscv”. Everything after the -Wl, will be sent to the linker, with following commas replaced with spaces.

If you call gcc instead of ld, then gcc will also add startfiles like crt0.o and libraries like libc.a, but you can disable that with --nostartfiles and --nostdlib. Gcc will also pass some of those options by default such as the -m elf32lriscv.

Generally, it is safer to call gcc to link, because a lot of special options are required by the linker, and knowledge of them are encoded in the gcc driver. But if you know what you are doing, you can call ld directly.

I’m not a freedomstudio expert, so I don’t know how to tell it to call ld instead of gcc.

1 Like