C++ gcc arm错误:';::文件编号';尚未申报
我正在尝试让spdlog在我的嵌入式项目中使用。(是的,我知道spdlog不是为嵌入式项目设计的,但我想尝试一下;)C++ gcc arm错误:';::文件编号';尚未申报,c++,arm,spdlog,C++,Arm,Spdlog,我正在尝试让spdlog在我的嵌入式项目中使用。(是的,我知道spdlog不是为嵌入式项目设计的,但我想尝试一下;) 我已经成功地将C++ STD::线程、STD::互斥体等转发给适当的FrReTOS对象。因此,这不再是一个问题 实际代码非常简单。数据应写入日志文件。实际文件写入应通过嵌入式FATFS库完成 #include <spdlog/logger.h> void foo() { // create a file rotating logger with 5mb size
我已经成功地将C++ STD::线程、STD::互斥体等转发给适当的FrReTOS对象。因此,这不再是一个问题
实际代码非常简单。数据应写入日志文件。实际文件写入应通过嵌入式FATFS库完成#include <spdlog/logger.h>
void foo()
{
// create a file rotating logger with 5mb size max and 3 rotated files
auto file_logger = spdlog::rotating_logger_mt("file_logger", "myfilename", 1024 * 1024 * 5, 3);
}
现在我已经有了一个系统调用的包装器
int _open(char *path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
}
int _close(int file)
{
return -1;
}
__attribute__((weak)) int _read(int file, char *ptr, int len)
{
return -1;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
return -1;
}
为什么我仍然会出错?
我必须补充吗
--wrap=_read
--wrap=_write
等链接器标志
你能帮我一下吗?嘿,伙计们,你们说得对。 这是一个编译器错误,而不是链接器错误。 我加了一份声明
int fileno(FILE *stream)
{
errno = ENOENT;
return -1;
}
在spdlog之前包括。
这就解决了问题
@蒂姆:不幸的是,spdlog现在不支持裸机平台:O
第231行:
// OpenBSD doesn't compile with :: before the fileno(..)
#if defined(__OpenBSD__)
int fd = fileno(f);
#else
int fd = ::fileno(f);
#endif
错误很明显-您的spdlog库正试图使用
fileno()
函数获取文件描述符,但这是不受支持的。注意,这是一个编译器错误,因此链接器标志在这里不能帮助您。您可以尝试模拟fileno
和isatty
。正确的方法是将os inl.h
文件替换为适合您的操作系统的文件。这是从spdlog到stdio的翻译。他们可能有定义来选择他们正在使用的stdio。
// OpenBSD doesn't compile with :: before the fileno(..)
#if defined(__OpenBSD__)
int fd = fileno(f);
#else
int fd = ::fileno(f);
#endif