【发布时间】:2020-11-11 06:40:32
【问题描述】:
我正在尝试使用 `#include stat() 函数,但是每当我调用它时都会收到此错误:
...toolchains/gcc-arm-none-eabi-8-2018/arm-gcc-macos/arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(lib_a-statr.o): in function `_stat_r':
statr.c:(.text._stat_r+0xe): undefined reference to `_stat'
这是我的文件(我已经列出了所有包含的内容,我知道有些可能与此问题无关,但我已经列出了所有内容):
#include <kernel.h>
#include <device.h>
#include <drivers/i2c.h>
#include <sys/__assert.h>
#include <logging/log.h>
#include <sys/printk.h>
#include <soc.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#define SOURCE_FILE "battery.gm.fs"
int write_to_dev(struct device* dev)
{
struct stat st;
int nSourceFile;
char *pFileBuffer;
stat(SOURCE_FILE, &st); // problematic line
// other code here
}
每当我打电话给write_to_dev() 时,我都会遇到这个问题。我的代码基于此链接的第 17 页:https://www.ti.com/lit/an/slua801/slua801.pdf?ts=1595360845070&ref_url=https%253A%252F%252Fwww.google.com%252F 感谢您的帮助!
编辑:我正在使用带有 zephyr RTOS 和 TI BQ27621 电量计的 STM32 芯片
【问题讨论】:
-
也许这个答案可以帮助你:Answer
-
@PurpleSpark:它是裸机还是任何嵌入式 Linux 处理器?请指定您使用的是哪个特定的 TI 处理器或控制器。
-
@GauravPathak 它在 STM32 处理器上。我正在使用 Zephyr RTOS。我也会用这个更新我的问题
-
@PurpleSpark:第 17 页上的代码适用于 Linux 用户空间应用程序,不适用于裸机纯固件。
-
所以,不,您的平台上没有
stat,您的平台环境没有实现 posix 或其他操作系统标准,没有底层文件系统,这毫无意义。 Zeprhy can be configured 支持有意义的 posix 函数子集,但对于 I/O,您必须自己实现它们。您希望文件"battery.gm.fs"位于何处?闪现?在内存中?在外部 SD 卡中?
标签: c embedded firmware texas-instruments