我正在尝试让 spdlog 用于我的嵌入式项目。(是的,我知道 spdlog 不是为嵌入式项目设计的,但我想试一试;))
我已经设法将 c++ std::thread、std::mutex 等转发到适当的 FreeRTOS 对象。所以这不再是问题了。
实际代码非常简单。数据应写入日志文件。实际的文件写入应通过嵌入式 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);
}
但是,这会导致编译器错误
../User/ThirdParty/spdlog/details/os-inl.h: In function 'size_t spdlog::details::os::filesize(FILE*)':
../User/ThirdParty/spdlog/details/os-inl.h:231:16: error: '::fileno' has not been declared
231 | int fd = ::fileno(f);
| ^~~~~~
../User/ThirdParty/spdlog/details/os-inl.h: In function 'bool spdlog::details::os::in_terminal(FILE*)':
../User/ThirdParty/spdlog/details/os-inl.h:432:21: error: 'fileno' was not declared in this scope; did you mean 'file'?
432 | return ::isatty(fileno(file)) != 0;
| ^~~~~~
| file
现在我已经有了系统调用的包装器
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
等到链接器标志?
你能帮帮我吗?