【发布时间】:2019-12-17 01:43:09
【问题描述】:
我正在使用 gcc-arm-none-eabi 工具链(当前为 7.2.1)设置和环境。这是针对 ARM cortex M4 嵌入式设备的。
我想为整个项目重新定义 printf,但我遇到了麻烦。我想使用this 实现。我已经将它安装到项目中,我可以通过调用来使用它,例如:printf_("Test: %i",5);,一切都按预期工作。
现在我想将它设置为默认的 printf 函数。如果我取消注释:#define printf printf_,我会收到以下错误:
/home/timv/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/arm-none-eabi/include/c++/7.2.1/cstdio:127:11: error: '::printf' has not been declared
using ::printf;
稍后:
src/LoggerTask.cpp:62:5: error: 'printf' was not declared in this scope
在那个文件中我找到了这一行:
#undef printf
当我注释掉该行时,项目构建,并且 printf 工作。这很好,但我想在不修补工具链的情况下拥有我的项目功能。
我该怎么做呢?还有哪些有用的信息?
【问题讨论】:
-
您需要 C 解决方案还是只需要 C++ 解决方案?
-
您为什么要在您的
LoggerTask.cpp中添加#undef printf?f I uncomment: #define printf printf_- 定义位于哪个文件中? -
重新定义标准 C 名称是一个坏主意(令人困惑,并且可能是未定义的行为)。你不能在你的源代码中使用
myprintf吗?
标签: c++ c arm embedded platformio