使用GCC Arm工具链开发的项目, 在11.2下编译正常, 但是升级到 arm-gnu-toolchain-11.3.rel1 以及 arm-gnu-toolchain-12.2 之后, 编译出现警告

/opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(libc_a-closer.o): in function `_close_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/closer.c:47: warning: _close is not implemented and will always fail
/opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(libc_a-fstatr.o): in function `_fstat_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/fstatr.c:55: warning: _fstat is not implemented and will always fail
/opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(libc_a-isattyr.o): in function `_isatty_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/isattyr.c:52: warning: _isatty is not implemented and will always fail
/opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(libc_a-lseekr.o): in function `_lseek_r':
/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/reent/lseekr.c:49: warning: _lseek is not implemented and will always fail

这是因为使用了printf, 定义了 int _read(int file, char *ptr, int len)int _write(int file, char *ptr, int len)方法但是未定义其它方法所致.

一个完整的输入输出重定向需要包含以下函数, 把剩下的都补齐就不会提示警告了

int _isatty(int fd);
int _write(int fd, char* ptr, int len);
int _close(int fd);
int _lseek(int fd, int ptr, int dir);
int _read(int fd, char* ptr, int len);
int _fstat(int fd, struct stat* st);

首先引入必要的头文件

#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>

然后是固定的方法


__attribute__((weak)) int _isatty(int fd)
{
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
return 1; errno = EBADF;
return 0;
} __attribute__((weak)) int _close(int fd)
{
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
return 0; errno = EBADF;
return -1;
} __attribute__((weak)) int _lseek(int fd, int ptr, int dir)
{
(void)fd;
(void)ptr;
(void)dir; errno = EBADF;
return -1;
} __attribute__((weak)) int _fstat(int fd, struct stat *st)
{
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
{
st->st_mode = S_IFCHR;
return 0;
} errno = EBADF;
return 0;
}

_read 和 _write 是与底层硬件实现相关的, 需要自己实现对应的字符输入和输出


__attribute__((weak)) int _read(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}
return len;
} __attribute__((weak)) int _write(int file, char *ptr, int len)
{
(void)file;
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}

GCC Arm 11.3rel1, 12.2编译提示 _close is not implemented and will always fail的更多相关文章

  1. GCC Arm 12.2编译提示 LOAD segment with RWX permissions 警告

    使用GCC Arm工具链开发的项目, 在升级到 arm-gnu-toolchain-12.2 之后, 编译出现警告 arm-gnu-toolchain-12.2.mpacbti-bet1-x86_64 ...

  2. busybox-1.12.2编译提示“混合的隐含和普通规则”错误解决

    编译环境:CentOs 7.1 Ubuntu 12.0.4 都可以 交叉编译工具:gcc -4.3.2 (博创6410平台) 问题描述:执行make menuconfig命令的时候,提示Makefil ...

  3. Ubuntu 22.04 GCC Arm 12.2.rel1编译 DAPLink

    ARMmbed / DAPLink 项目 仓库地址 https://github.com/ARMmbed/DAPLink Arm Mbed 应该属于Arm的机构或者是Arm资助的机构. 常用的 DAP ...

  4. MAC 下编译 ANDROID P 源码 提示 internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12" "10.13"]

    MAC 下编译 ANDROID P 源码出现下面的问题: ninja: no work to do. [21/21] out/soong/.bootstrap/bin/soong_build out/ ...

  5. linux gcc 区分32位或64位编译 && 请问arm存储,是以小端格式还是以大端格式?

    linux gcc 区分32位或64位编译   Linux系统下程序如何区分是64位系统还是32位系统 经过对include的翻查,最后确定gcc以__i386__来 进行32位编码,而以__x86_ ...

  6. (二十三)ARM平台NEON指令的编译和优化

    ARM平台NEON指令的编译和优化 本文介绍了ARM平台基于ARM v7-A架构的ARM Cortex-A系列处理器(Cortex-A5, Cortex-A7,Cortex-A8, Cortex-A9 ...

  7. MacOS Sierra10.12.4编译Android7.1.1源代码必须跳的坑

    简单介绍 下载Android7.1.1源代码花费了两天,编译整个源代码相同花费了2天,期间遇到无数个坑. 如今编译源代码,一旦中间遇到错误,则要又一次開始. 本文记录编译过程遇到的问题及解决方式,如有 ...

  8. Ubuntu 11.10 (Oneiric)上编译带utrace补丁的内核 转

    Ubuntu 11.10 (Oneiric)上编译带utrace补丁的内核 首先准备linux内核编译环境: sudo apt-get install fakeroot build-essential ...

  9. 在VS13上编译通过的代码放在12上编译-错误:l __dtoui3 referenced in function _event_debug_map_HT_GROW

    在VS13上编译通过的代码放在12上编译 遇到错误:l __dtoui3 referenced in function _event_debug_map_HT_GROW 1>------ 已启动 ...

  10. nginx-1.12.2编译安装指导

    nginx-1.12.2编译安装 下载源码包 安装 安装后配置 下载源码包 下载地址:http://nginx.org/en/download.html nginx-1.12.2:http://ngi ...

随机推荐

  1. 聊聊x86计算机启动发生的事?

    大家好,我是呼噜噜,最近在看linux早期内核0.12的源码,突然想到一个困扰自己好久的问题:当我们按下电源键,计算机发生了什么?神秘地址0x7C00究竟是什么?操作系统又是如何被加载到硬件中的?带着 ...

  2. [转帖]TiDB 数据库核心原理与架构 [TiDB v6](101)笔记

    https://www.jianshu.com/p/01e49a93f671 description: "本课程专为将在工作中使用 TiDB 数据库的开发人员.DBA 和架构师设计. 本门课 ...

  3. [转帖]比快更快的 ELK 8 安装使用指南-Elasticsearch,Kibana,Logstash

    https://juejin.cn/post/7133907643386560519 携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第23天,点击查看活动详情 Elastic 8 ...

  4. [转帖]Linux下使用 ipset 封大量IP及ipset参数说明

    https://www.cnblogs.com/xiaofeng666/p/10952627.html Linux使用iptables封IP,是常用的应对网络攻击的方法,但要封禁成千上万个IP,如果添 ...

  5. [转帖]nginx的luajit安装luarocks并安装luafilesystem

    nginx的luajit安装luarocks并安装luafilesystem by admin on 2015-07-11 08:05:23 in , 69次 标题有点绕口.我尽量把关键词都贴进去.之 ...

  6. [转帖]CPU计算性能speccpu2006的测试方法及工具下载

    https://www.yii666.com/blog/335517.html CPU计算性能speccpu2006的测试方法及工具下载 简介 测试原理 目录结构 测试方法 基准测试项解析 测试结果 ...

  7. [转帖]查看x86 cpu睿频命令

    查看cpu是否开启睿频,offline掉一些cpu核心后,查看cpu睿频是否升高? turbostat统计X86 处理器的频率.空闲状态.电源状态.温度等状态等 [root@rootbird~]# t ...

  8. NativeMemoryTracking的再学习

    摘要 最近一段时间学习jvm比较多. 为了能够更加深入的进行一些调优和峰值性能的配置. 看了很多像是NMT,inline,堆区方法区以及分层编译等知识. 但是看到华为毕昇社区说的codecache相关 ...

  9. nginx 反向代理 负载均衡的做法

    项目上使用负载均衡的方法, 感觉最简单的办法其实是 http的 upstream  注意需要保留端口号信息. worker_processes 4; events { worker_connectio ...

  10. Orika JavaBean映射工具使用

    作者:京东零售 张宾 1.Orika是什么? Orika是一个简单.快速的JavaBean拷贝框架,它能够递归地将数据从一个JavaBean复制到另一个JavaBean,这在多层应用开发中是非常有用的 ...