使用 sprintf() 时未定义对 __mulhi3 的引用 - Windows 上 Code::Blocks 中的 AVR GCC

Undefined reference to __mulhi3 when using sprintf() - AVR GCC in Code::Blocks on Windows

提问人:ololuki 提问时间:9/22/2018 最后编辑:ololuki 更新时间:9/23/2018 访问量:742

问:

我正在使用 Microchip (Atmel) 的 AVR-GCC 工具链的 Code::Blocks。我正在尝试编译程序。当我尝试编译使用函数的程序时,我得到“未定义的引用”。没有这个函数,我不会出错。在 Atmel Studio 或 Linux 下的 Code::Blocks 中编译的相同程序工作正常。Atmega32__mulhi3sprintf()

#include <avr/io.h>
#include <stdio.h>

int main(void)
{
    char buf[20];
    sprintf(buf, "Hello %d", 1);

    while(1);
    return 0;
}
代码块 AVR 未定义引用 AVR-GCC

评论


答:

1赞 ololuki 9/22/2018 #1

问题是由 的 Code::Blocks 的默认设置引起的 - 存在不必要的包含路径。你应该去GNU GCC Compiler for AVRC:/WinAVR/avr/lib

编译器→设置...→ GNU GCC 编译器,用于 AVR → 搜索指导→链接器

并清除包含路径列表。如果列表不为空,链接器将尝试链接到错误版本的库。