'Failed linking for RV32I ISA

I have compiled a test file written in C to an object file, stripped the symbols because I need as much memory as I can get, and now I got to the point where I need to link .o file but I get the following error:

riscv64-unknown-elf-ld: test.o: ABI is incompatible with that of the selected emulation: target emulation 'elf32-littleriscv' does not match 'elf64-littleriscv'

commands I ran:

riscv64-unknown-elf-gcc test.o -c -march=rv32i -mabi=ilp32 
riscv64-unknown-elf-strip test.o 
riscv64-unknown-elf-ld test.o

If somebody can help I would be grateful, regular compilation works just fine so I know that there exists a combination of commands which would work just I can't find anything on running a RISCV linker with options.



Sources

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

Source: Stack Overflow

Solution Source