我在进行基本编译时遇到困难。在Windows 7-64bit平台上链接RISCV上最新的RISCV GCC。
安装的工具:7.1.1-2-20170912-2255来自https://github.com/gnu-mcu-eclipse/riscv-none-gcc/releases/
平台:Windows 7,64位,没有cygwin
计划:
#include <stdint.h>
int32_t iBlahblah;
int main (void)
{
while(1)
iBlahblah++;
return 0;
}
命令行:
"c:\Program Files\GNU MCU Eclipse\RISC-V Embedded GCC\7.1.1-2-20170912-2255\bin\riscv64-unknown-elf-gcc.exe" -c hello.c -o hello -march=rv32imac -mabi=ilp32 -Os
"c:\Program Files\GNU MCU Eclipse\RISC-V Embedded GCC\7.1.1-2-20170912-2255\bin\riscv64-unknown-elf-gcc.exe" -o hello.elf -march=rv32imac -mabi=ilp32 -Os -Wl,-Map=hello.lst hello.o
输出:
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: hello.o: ABI is incompatible with that of the selected emulation: target emulation `elf64-littleriscv' does not match `elf32-littleriscv'
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: failed to merge target specific data of file hello.o
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/lib/rv32imac/ilp32\libg.a(lib_a-exit.o): In function `.L0 ': exit.c:(.text.exit+0x1e): undefined reference to `_exit'
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: hello.elf(.text): relocation "iBlahblah+0x0 (type R_RISCV_HI20)" goes out of range
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: hello.o: file class ELFCLASS64 incompatible with ELFCLASS32
c:/program files/gnu mcu eclipse/risc-v embedded gcc/7.1.1-2-20170912-2255/bin/../lib/gcc/riscv64-unknown-elf/7.1.1/../../../../riscv64-unknown-elf/bin/ld.exe: final link failed: File in wrong format
collect2.exe: error: ld returned 1 exit status
最大的问题是如何解决&#34; ABI与所选仿真的不兼容&#34;?我们可以忽略有关重定位,退出等的其他问题,因为我的大型构建环境负责这一点(它为许多平台构建,目前不是RISCV)。
答案 0 :(得分:0)
riscv64-unknown-elf-gcc.exe -c hello.c -o hello -march = rv32imac -mabi = ilp32 -Os
这部分是错误的。您的gcc tolchain文档说https://gnu-mcu-eclipse.github.io/toolchain/riscv/
riscv64-unknown-elf-gcc vs riscv32-unknown-elf-gcc 在支持大量架构和系统的情况下,GCC建议在二进制文件前加上一个独特的元组:
<arch>-<vendor>-<os>-<libc/abi>-
裸机工具链的当前RISC-V前缀是riscv64-unknown-elf-和riscv32-unknown-elf - 。
好吧,不要被这个不幸的名字搞糊涂。 64或32连接到体系结构......这并不意味着编译器生成64位或32位RISC-V二进制文件。实际上,编译器基于-march和-mabi生成32/64位二进制文件。唯一的区别是默认值,当调用编译器时没有在命令行上显式设置-march和-mabi。
尝试使用riscv32-unknown-elf-gcc.exe来编译32位riscv平台的程序(arch&amp; abi名称中包含r32
&amp; 32
个部分),它应该使用正确的32位CRT文件。
对于multilib有一些支持,当riscv64将搜索32位库(https://gnu-mcu-eclipse.github.io/toolchain/riscv/#multiple-libraries,https://gnu-mcu-eclipse.github.io/blog/2017/09/13/riscv-none-gcc-v7-1-1-2-20170912-released/,https://gcc.gnu.org/onlinedocs/gccint/Target-Fragment.html MULTILIB_OPTIONS时),但出了点问题。请发布gcc -v .... -o your_program.bin
个结果,包括riscv32编译器,riscv64编译器和几个march / mabi组合。