RISC-V 未定义对“memcpy”的引用

如何解决RISC-V 未定义对“memcpy”的引用

我正在使用 RISC-V 32E 工具链来编译一些独立的 CPP 代码。我在下面遇到错误。

/opt/riscv32i/bin/riscv32-unknown-elf-g++ -Os -ffreestanding -o firmware/firmware.elf \
    -Wl,-Bstatic,-T,firmware/sections.lds,-Map,firmware/firmware.map,--strip-debug \
    firmware/start.o firmware/print.o  firmware/stream.o firmware/main.o firmware/accel.o firmware/data_redir_m.o  -lgcc -fno-threadsafe-statics -nostdlib 
/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/../../../../riscv32-unknown-elf/bin/ld: firmware/data_redir_m.o: in function `.L31':
data_redir_m.cpp:(.text+0x442): undefined reference to `memcpy'
collect2: error: ld returned 1 exit status
Makefile:46: recipe for target 'firmware/firmware.elf' failed
make: *** [firmware/firmware.elf] Error 1

我想保持 hex 文件尽可能小,所以我的偏好是不使用 -lstdc++ 库。让我很困惑的是,为什么即使我在 data_redir_m.cpp 文件中手动添加 memcpy() 函数定义,它仍然会抱怨此类错误。

#include "typedefs.h"

void * memcpy ( void * destination,const void * source,int num ){
  int i=0;
  *((int*)destination) = *((int*)source);
}

static int check_clockwise( Triangle_2D triangle_2d )
{
  int cw;

  cw = (triangle_2d.x2 - triangle_2d.x0) * (triangle_2d.y1 - triangle_2d.y0)
       - (triangle_2d.y2 - triangle_2d.y0) * (triangle_2d.x1 - triangle_2d.x0);

  return cw;

}

// swap (x0,y0) (x1,y1) of a Triangle_2D
static void clockwise_vertices( Triangle_2D *triangle_2d )
{

  bit8 tmp_x,tmp_y;

  tmp_x = triangle_2d->x0;
  tmp_y = triangle_2d->y0;

  triangle_2d->x0 = triangle_2d->x1;
  triangle_2d->y0 = triangle_2d->y1;

  triangle_2d->x1 = tmp_x;
  triangle_2d->y1 = tmp_y;

}



// find the min from 3 integers
static bit8 find_min( bit8 in0,bit8 in1,bit8 in2 )
{
  if (in0 < in1)
  {
    if (in0 < in2)
      return in0;
    else
      return in2;
  }
  else
  {
    if (in1 < in2)
      return in1;
    else
      return in2;
  }
}


// find the max from 3 integers
static bit8 find_max( bit8 in0,bit8 in2 )
{
  if (in0 > in1)
  {
    if (in0 > in2)
      return in0;
    else
      return in2;
  }
  else
  {
    if (in1 > in2)
      return in1;
    else
      return in2;
  }
}


// project a 3D triangle to a 2D triangle
void projection(
        bit32 input_lo,bit32 input_mi,bit32 input_hi,Triangle_2D *triangle_2d
        )
{
  #pragma HLS INLINE off
  Triangle_3D triangle_3d;
  // Setting camera to (0,-1),the canvas at z=0 plane
  // The 3D model lies in z>0 space
  // The coordinate on canvas is proportional to the corresponding coordinate
  // on space

    bit2 angle = 0;
    triangle_3d.x0 = bit8(input_lo( 7,0));
    triangle_3d.y0 = bit8(input_lo(15,8));
    triangle_3d.z0 = bit8(input_lo(23,16));
    triangle_3d.x1 = bit8(input_lo(31,24));
    triangle_3d.y1 = bit8(input_mi( 7,0));
    triangle_3d.z1 = bit8(input_mi(15,8));
    triangle_3d.x2 = bit8(input_mi(23,16));
    triangle_3d.y2 = bit8(input_mi(31,24));
    triangle_3d.z2 = bit8(input_hi( 7,0));

  if(angle == 0)
  {
    triangle_2d->x0 = triangle_3d.x0;
    triangle_2d->y0 = triangle_3d.y0;
    triangle_2d->x1 = triangle_3d.x1;
    triangle_2d->y1 = triangle_3d.y1;
    triangle_2d->x2 = triangle_3d.x2;
    triangle_2d->y2 = triangle_3d.y2;
    triangle_2d->z  = triangle_3d.z0 / 3 + triangle_3d.z1 / 3 + triangle_3d.z2 / 3;
  }

  else if(angle == 1)
  {
    triangle_2d->x0 = triangle_3d.x0;
    triangle_2d->y0 = triangle_3d.z0;
    triangle_2d->x1 = triangle_3d.x1;
    triangle_2d->y1 = triangle_3d.z1;
    triangle_2d->x2 = triangle_3d.x2;
    triangle_2d->y2 = triangle_3d.z2;
    triangle_2d->z  = triangle_3d.y0 / 3 + triangle_3d.y1 / 3 + triangle_3d.y2 / 3;
  }

  else if(angle == 2)
  {
    triangle_2d->x0 = triangle_3d.z0;
    triangle_2d->y0 = triangle_3d.y0;
    triangle_2d->x1 = triangle_3d.z1;
    triangle_2d->y1 = triangle_3d.y1;
    triangle_2d->x2 = triangle_3d.z2;
    triangle_2d->y2 = triangle_3d.y2;
    triangle_2d->z  = triangle_3d.x0 / 3 + triangle_3d.x1 / 3 + triangle_3d.x2 / 3;
  }

}



// calculate bounding box for a 2D triangle
void rasterization1 (
        Triangle_2D triangle_2d,hls::stream<ap_uint<32> > & Output_1,hls::stream<ap_uint<32> > & Output_2
        )
{
    Triangle_2D triangle_2d_same;
    bit8 max_min[5];
    max_min[0]=0;
    max_min[1]=0;
    max_min[2]=0;
    max_min[3]=0;
    max_min[4]=0;
    bit16 max_index[1];
    max_index[0]=0;
    bit32 tmp1,tmp2,tmp3,tmp4;
    static int parity = 0;
  #pragma HLS INLINE off
  // clockwise the vertices of input 2d triangle
  if ( check_clockwise( triangle_2d ) == 0 ){

    tmp1(7,0) = 1;
    tmp1(15,8) = triangle_2d_same.x0;
    tmp1(23,16) = triangle_2d_same.y0;
    tmp1(31,24) = triangle_2d_same.x1;
    tmp2(7,0) = triangle_2d_same.y1;
    tmp2(15,8) = triangle_2d_same.x2;
    tmp2(23,16) = triangle_2d_same.y2;
    tmp2(31,24) = triangle_2d_same.z;

    tmp3(15,0) = max_index[0];
    tmp3(23,16) = max_min[0];
    tmp3(31,24) = max_min[1];

    tmp4(7,0) = max_min[2];
    tmp4(15,8) = max_min[3];
    tmp4(23,16) = max_min[4];
    tmp4(31,24) = 0;
    if(parity==0){
        Output_1.write(tmp1);
        Output_1.write(tmp2);
        Output_1.write(tmp3);
        Output_1.write(tmp4);
        parity = 1;
    }else{
        Output_2.write(tmp1);
        Output_2.write(tmp2);
        Output_2.write(tmp3);
        Output_2.write(tmp4);
        parity = 0;
    }
#ifdef PROFILE
  data_redir_m_out_1+=4;
#endif

    return;
  }
  if ( check_clockwise( triangle_2d ) < 0 )
    clockwise_vertices( &triangle_2d );




  // copy the same 2D triangle
  triangle_2d_same.x0 = triangle_2d.x0;
  triangle_2d_same.y0 = triangle_2d.y0;
  triangle_2d_same.x1 = triangle_2d.x1;
  triangle_2d_same.y1 = triangle_2d.y1;
  triangle_2d_same.x2 = triangle_2d.x2;
  triangle_2d_same.y2 = triangle_2d.y2;
  triangle_2d_same.z  = triangle_2d.z ;

  // find the rectangle bounds of 2D triangles
  max_min[0] = find_min( triangle_2d.x0,triangle_2d.x1,triangle_2d.x2 );
  max_min[1] = find_max( triangle_2d.x0,triangle_2d.x2 );
  max_min[2] = find_min( triangle_2d.y0,triangle_2d.y1,triangle_2d.y2 );
  max_min[3] = find_max( triangle_2d.y0,triangle_2d.y2 );
  max_min[4] = max_min[1] - max_min[0];

  // calculate index for searching pixels
  max_index[0] = (max_min[1] - max_min[0]) * (max_min[3] - max_min[2]);

  tmp1(7,0) = 0;
  tmp1(15,8) = triangle_2d_same.x0;
  tmp1(23,16) = triangle_2d_same.y0;
  tmp1(31,24) = triangle_2d_same.x1;

  tmp2(7,0) = triangle_2d_same.y1;
  tmp2(15,8) = triangle_2d_same.x2;
  tmp2(23,16) = triangle_2d_same.y2;
  tmp2(31,24) = triangle_2d_same.z;

  tmp3(15,0) = max_index[0];
  tmp3(23,16) = max_min[0];
  tmp3(31,24) = max_min[1];

  tmp4(7,0) = max_min[2];
  tmp4(15,8) = max_min[3];
  tmp4(23,16) = max_min[4];
  tmp4(31,24) = 0;

  if(parity==0){
    Output_1.write(tmp1);
    Output_1.write(tmp2);
    Output_1.write(tmp3);
    Output_1.write(tmp4);
    parity = 1;
  }else{
    Output_2.write(tmp1);
    Output_2.write(tmp2);
    Output_2.write(tmp3);
    Output_2.write(tmp4);
    parity = 0;
  }
  return;
}


void data_redir_m (
        hls::stream<ap_uint<32> > & Input_1,hls::stream<ap_uint<32> > & Output_2
        )
{
#pragma HLS INTERFACE ap_hs port=Input_1
#pragma HLS INTERFACE ap_hs port=Output_1
#pragma HLS INTERFACE ap_hs port=Output_2

  bit32 input_lo;
  bit32 input_mi;
  bit32 input_hi;
  bit128 input_tmp;

  hls::stream<ap_uint<32> > Output_1_1;
  hls::stream<ap_uint<32> > Output_2_2;
  Triangle_2D triangle_2ds_1;
  Triangle_2D triangle_2ds_2;



  input_lo = Input_1.read();
  input_mi = Input_1.read();
  input_hi = Input_1.read();
#ifdef PROFILE
  data_redir_m_in_1+=3;
#endif

  projection (input_lo,input_mi,input_hi,&triangle_2ds_1);
  rasterization1 (triangle_2ds_1,Output_1,Output_2);

}

解决方法

如果要为非os环境搭建gcc,需要提前搭建newlib。并告诉gcc去哪里找libc,方式是在配置项目的时候声明sysroot。

您可以使用此脚本(ian910297/build-riscv-gnu-toolchain) 来构建 riscv gnu 工具链。如果选择此方法,请注意目录名称。

否则,riscv 官方也提供了类似的脚本来构建,如:riscv/riscv-gnu-toolchain)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-